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
51
52
53
|
# File 'lib/pendulum/runner.rb', line 7
def run(argv=ARGV)
api_key = ENV['TD_API_KEY']
mode = nil
dry_run = false
force = false
color = true
options = {
file: DEFAULT_SCHEDFILE,
env: :development,
}
output = DEFAULT_SCHEDFILE
opt.on('-k', '--apikey=KEY') {|v| api_key = v }
opt.on('-a', '--apply') { mode = :apply }
opt.on('-E', '--environment=ENV') {|v| options[:env] = v }
opt.on('-f', '--file=FILE') {|v| options[:file] = v }
opt.on('', '--dry-run') { dry_run = true }
opt.on('', '--force') { force = true }
opt.on('', '--no-color') { color = false }
opt.on('-e', '--export') do
mode = :export
options.delete(:file)
end
opt.on('-o', '--output=FILE') {|v| output = v }
opt.parse!(argv) rescue return usage $!
return usage if (api_key.nil? || mode.nil?)
begin
client = Client.new(api_key, options)
case mode
when :apply
client.apply(dry_run: dry_run, force: force, color: color)
when :export
client.export(output)
end
rescue
$stderr.puts $!
return 1
end
return 0
end
|