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
|
# File 'lib/debra/cli.rb', line 10
def exec
options = OpenStruct.new
OptionParser.new do |opts|
opts.banner = 'Usage: debra [options]'
opts.on("-h", "--help", "Show this message") {|h| options.help = h}
opts.on("-r", "--revision revision", "Append a revision to the file, useful if you are doing CI") {|r| options.revision = r}
opts.on("-v", "--verbose", "Run verbosely") {|v| options.verbose = v}
opts.on("-ffile", "--file file", String, "Load a specific Debfile") {|f| options.file = f}
opts.on("--version", "Show version") do
puts "Debra " + Debra::VERSION.join('.')
exit
end
begin
opts.parse!
rescue OptionParser::MissingArgument,
OptionParser::InvalidOption,
OptionParser::InvalidArgument => e
puts e.message + ', use --help for more details'
exit 1
end
if !options.file.nil? && !File.exists?(options.file)
puts "Cannot find file #{options.file}"
exit 1
end
if options.help
puts opts
exit 1
end
end
options.file = options.file || find_debfile
run options
end
|