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
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
|
# File 'lib/vmreverter/options.rb', line 9
def self.parse_args
return @options if @options
@no_args = ARGV.empty? ? true : false
@defaults = {}
@options = {}
@options_from_file = {}
optparse = OptionParser.new do|opts|
opts.banner = "Usage: #{File.basename($0)} [options...]"
@defaults[:auth] = File.join(ENV['HOME'], '.fog')
opts.on '-a', '--auth FILE',
'Use authentication FILE',
"Default: #{@defaults[:auth]}" do |file|
@options[:auth] = file
end
@defaults[:config] = nil
opts.on '-c', '--config FILE',
'Use configuration FILE',
"Default: #{@defaults[:config]}" do |file|
@options[:config] = file
end
@defaults[:options_file] = nil
opts.on '-o', '--options-file FILE',
'Read options from FILE',
'This should evaluate to a ruby hash.',
'CLI optons are given precedence.' do |file|
@options_from_file = parse_options_file file
end
@defaults[:quiet] = false
opts.on '-q', '--[no-]quiet',
'Do not log output to STDOUT',
'(default: false)' do |bool|
@options[:quiet] = bool
end
@defaults[:color] = true
opts.on '--[no-]color',
'Do not display color in log output',
'(default: true)' do |bool|
@options[:color] = bool
end
@defaults[:debug] = false
opts.on '--[no-]debug',
'Enable full debugging',
'(default: false)' do |bool|
@options[:debug] = bool
end
opts.on_tail("-h","--help","Display this screen") do
puts opts
exit
end
end
optparse.parse!
puts optparse if @no_args
@options = @options_from_file.merge(@options)
@options = @defaults.merge(@options)
@options
end
|