7
8
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
|
# File 'lib/check_from_file/cli.rb', line 7
def self.parse(args)
options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{$0} -c <command> -o <stdout> -e <stderr> -r <ret>"
opts.on('-c', '--command COMMAND', :REQUIRED, 'Command that was run to generate this output') do |command|
options[:command] = command
end
opts.on('-o', '--stdout FILE', 'File that contains STDOUT') do |stdout|
options[:stdout] = stdout
end
opts.on('-e', '--stderr FILE', 'File that contains STDERR') do |stderr|
options[:stderr] = stderr
end
opts.on('-r', '--return FILE', 'File that contains return code') do |ret|
options[:return] = ret
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("--version", "Show version") do
puts CheckFromFile::VERSION
exit
end
end
opt_parser.parse!(args)
%w(command stdout stderr return).each do |opt|
if options[opt.to_sym].nil?
puts "Missing required option #{opt}"
puts opt_parser
exit 1
end
end
options
end
|