9
10
11
12
13
14
15
16
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
|
# File 'lib/done_log/options.rb', line 9
def self.parse!(args)
options = {}
days = args.grep(/^-\d+$/)
unless days.empty?
if days.length > 1
raise "Expected only one day, got #{days.inspect}"
end
days = days.first
args.delete days
options[:time_period] = Date.today - days.to_i.abs
options[:action] ||= :edit
end
OptionParser.new do |opts|
opts.banner = "Usage: done_log [options]"
opts.on "-NUM", OptionParser::DecimalInteger, "Go back NUM days"
opts.on "-e", "--edit", "Edit log(s)" do
options[:action] = :edit
end
opts.on "-s", "--show", "Display log(s)" do
options[:action] = :show
end
opts.on "-d", "--date [DATE]", Date, "Select date" do |date|
options[:time_period] = date
end
opts.on "--sprint", "Last 14 days" do
options[:time_period] = (Date.today - 14)..Date.today
options[:action] ||= :show
end
opts.on "-c", "--color-date COLOR", Done::ANSIColors.colors, "Set color for dates" do |color|
options[:date_color] = color.to_sym
end
opts.on_tail "-h", "--help", "Show this message" do
puts opts
exit
end
end.parse(args)
default_options.merge(options)
end
|