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:

  • The type

  • 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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|on)/
             '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 :time_display
    cmd.desc 'Show time intervals on @done tasks'
    cmd.switch i[t times], default_value: true, negatable: true

    cmd.desc 'Show elapsed time on entries without @done tag'
    cmd.switch [:duration]

    cmd.desc 'Show time totals at the end of output'
    cmd.switch [:totals], default_value: false, negatable: false

    cmd.desc 'Sort tags by (name|time)'
    default = Doing.setting('tag_sort').normalize_tag_sort || :name
    cmd.arg_name 'KEY'
    cmd.flag [:tag_sort], must_match: REGEX_TAG_SORT, default_value: default, type: TagSortSymbol

    cmd.desc 'Tag sort direction (asc|desc)'
    cmd.arg_name 'DIRECTION'
    cmd.flag [:tag_order], must_match: REGEX_SORT_ORDER, default_value: :asc, type: OrderSymbol

    cmd.desc 'Only show items with recorded time intervals'
    cmd.switch [:only_timed], default_value: false, negatable: false
  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 :time_filter
    cmd.desc 'View entries before specified time (e.g. 8am, 12:30pm, 15:00)'
    cmd.arg_name 'TIME_STRING'
    cmd.flag [:before], type: DateEndString

    cmd.desc 'View entries after specified time (e.g. 8am, 12:30pm, 15:00)'
    cmd.arg_name 'TIME_STRING'
    cmd.flag [:after], type: DateBeginString

    cmd.desc %(
      Time range to show `doing #{cmd.name} --from "12pm to 4pm"`
    )
    cmd.arg_name 'TIME_RANGE'
    cmd.flag [:from], type: DateRangeString, must_match: REGEX_TIME_RANGE
  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