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
59
60
61
|
# File 'lib/gemometer/cli.rb', line 16
def self.parse_args(args)
options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
opts.banner = 'Usage: gemometer [options]'
opts.separator ''
opts.separator 'Specific options:'
opts.on('-n', '--notifier NOTIFIER', NOTIFIERS, {},
'Specify the notifier app', " (#{NOTIFIERS.join(', ')})") do |notifier|
options.notifier = notifier
end
opts.on('-u', '--url URL',
'Specify the app notification url') do |url|
options.url = url
end
opts.separator ''
opts.separator 'Common options:'
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
opts.on_tail('--version', 'Show version') do
puts Gemometer::VERSION
exit
end
end
begin
opt_parser.parse!(args)
missing = MANDATORY.select{ |param| options.send(param).nil? }
if missing.any?
abort("\nMissing options: #{missing.join(', ')}\n\n\n#{opt_parser}")
end
rescue OptionParser::InvalidArgument, OptionParser::MissingArgument, OptionParser::InvalidOption
abort("\n#{$!}\n\n\n#{opt_parser}")
end
options
end
|