Sha256: cf110fbe2de16a53eedc0de9952c99744a6102c38ad4771aef71070c798aed35

Contents?: true

Size: 1.94 KB

Versions: 1

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

# @@on
desc 'List entries for a date'
long_desc %(Date argument can be natural language. "thursday" would be interpreted as "last thursday,"
and "2d" would be interpreted as "two days ago." If you use "to" or "through" between two dates,
it will create a range.)
arg_name 'DATE_STRING'
command :on do |c|
  c.example 'doing on friday', desc: 'List entries between 12am and 11:59PM last Friday'
  c.example 'doing on 12/21/2020', desc: 'List entries from Dec 21, 2020'
  c.example 'doing on "3d to 1d"', desc: 'List entries added between 3 days ago and 1 day ago'

  c.desc 'Section'
  c.arg_name 'NAME'
  c.flag %i[s section], default_value: 'All'

  add_options(:output_template, c)
  add_options(:time_display, c)
  add_options(:search, c)
  add_options(:tag_filter, c)
  add_options(:time_filter, c)
  add_options(:save, c)

  c.action do |_global_options, options, args|
    if options[:output] && options[:output] !~ Doing::Plugins.plugin_regex(type: :export)
      raise InvalidPlugin.new('output', options[:output])

    end

    raise MissingArgument, 'Missing date argument' if args.empty?

    date_string = args.join(' ').strip
    date_string = 'midnight to today 23:59' if date_string =~ /^tod(?:ay)?/i

    start, finish = date_string.split_date_range

    raise InvalidTimeExpression, "Unrecognized date string (#{date_string})" unless start

    message = "date interpreted as #{start}"
    message += " to #{finish}" if finish
    Doing.logger.debug('Interpreter:', message)

    options[:times] = true if options[:totals]
    options[:sort_tags] = options[:tag_sort]

    Doing::Pager.page @wwid.list_date([start, finish],
                                      options[:section],
                                      options[:times],
                                      options[:output],
                                      options).chomp

    Doing.config.save_view(options.to_view, options[:save].downcase) if options[:save]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doing-2.1.43 bin/commands/on.rb