Top Level Namespace

Defined Under Namespace

Modules: BooleanTermParser, Doing, GLI, PhraseParser, Status Classes: Array, FalseClass, Hash, Object, String, Symbol, Time, TrueClass

Instance Method Summary collapse

Instance Method Details

#add_options(type, cmd) ⇒ Object

Add presets of flags and switches to a command.

:add_entry => --noauto, --note, --ask, --editor, --back

:search => --search, --case, --exact

:tag_filter => --tag, --bool, --not, --val

:date_filter => --before, --after, --from

Parameters:

  • type (Symbol)

    The type

  • cmd

    The GLI command to which the options will be added



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/doing/add_options.rb', line 17

def add_options(type, cmd)
  cmd_name = cmd.name.to_s
  action = case cmd_name
           when /again/
             'Repeat'
           when /grep/
             'Search'
           when /mark/
             'Flag'
           when /(last|tags|view)/
             'Show'
           else
             cmd_name.capitalize
           end

  case type
  when :add_entry
    cmd.desc 'Exclude auto tags and default tags'
    cmd.switch %i[X noauto], default_value: false, negatable: false

    cmd.desc 'Include a note'
    cmd.arg_name 'TEXT'
    cmd.flag %i[n note]

    cmd.desc 'Prompt for note via multi-line input'
    cmd.switch %i[ask], negatable: false, default_value: false

    cmd.desc "Edit entry with #{Doing::Util.default_editor}"
    cmd.switch %i[e editor], negatable: false, default_value: false

    cmd.desc 'Backdate start date for new entry to date string [4pm|20m|2h|yesterday noon]'
    cmd.arg_name 'DATE_STRING'
    cmd.flag %i[b back started], type: DateBeginString
  when :search
    cmd.desc 'Filter entries using a search query, surround with slashes for regex (e.g. "/query.*/"),
            start with single quote for exact match ("\'query")'
    cmd.arg_name 'QUERY'
    cmd.flag [:search]

    cmd.desc 'Case sensitivity for search string matching [(c)ase-sensitive, (i)gnore, (s)mart]'
    cmd.arg_name 'TYPE'
    cmd.flag [:case], must_match: REGEX_CASE,
                      default_value: Doing.settings.dig('search', 'case').normalize_case,
                      type: CaseSymbol

    cmd.desc 'Force exact search string matching (case sensitive)'
    cmd.switch %i[x exact], default_value: Doing.config.exact_match?, negatable: Doing.config.exact_match?
  when :tag_filter
    cmd.desc 'Filter entries by tag. Combine multiple tags with a comma. Wildcards allowed (*, ?)'
    cmd.arg_name 'TAG'
    cmd.flag [:tag], type: TagArray

    cmd.desc 'Perform a tag value query ("@done > two hours ago" or "@progress < 50").
            May be used multiple times, combined with --bool'
    cmd.arg_name 'QUERY'
    cmd.flag [:val], multiple: true, must_match: REGEX_VALUE_QUERY

    cmd.desc "#{action} items that *don't* match search/tag filters"
    cmd.switch [:not], default_value: false, negatable: false

    cmd.desc 'Boolean used to combine multiple tags. Use PATTERN to parse + and - as booleans'
    cmd.arg_name 'BOOLEAN'
    cmd.flag [:bool], must_match: REGEX_BOOL,
                      default_value: :pattern,
                      type: BooleanSymbol
  when :date_filter
    if action =~ /Archive/
      cmd.desc 'Archive entries older than date (natural language).'
    else
      cmd.desc "#{action} entries older than date (natural language). If this is only a time (8am, 1:30pm, 15:00), all
              dates will be included, but entries will be filtered by time of day"
    end
    cmd.arg_name 'DATE_STRING'
    cmd.flag [:before], type: DateBeginString

    if action =~ /Archive/
      cmd.desc 'Archive entries newer than date (natural language).'
    else
      cmd.desc "#{action} entries newer than date (natural language). If this is only a time (8am, 1:30pm, 15:00), all
              dates will be included, but entries will be filtered by time of day"
    end
    cmd.arg_name 'DATE_STRING'
    cmd.flag [:after], type: DateEndString

    if action =~ /Archive/
      cmd.desc %(
          Date range (natural language) to archive: `doing archive --from "1/1/21 to 12/31/21"`.
        )
    else
      cmd.desc %(
        Date range (natural language) to #{action.downcase}, or a single day to filter on.
        To specify a range, use "to": `doing #{cmd_name} --from "monday 8am to friday 5pm"`.

        If values are only time(s) (6am to noon) all dates will be included, but entries will be filtered
        by time of day.
      )
    end
    cmd.arg_name 'DATE_OR_RANGE'
    cmd.flag [:from], type: DateRangeString
  end
end