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
|
# File 'lib/addons-client/cli.rb', line 10
def run_command!
command = Settings.rest.first
case command
when /list/i
response = client.list(Settings.rest[1..-1].join(" "))
response.data.each do |addon_plan|
puts "#{addon_plan["name"]} $%0.2f/#{addon_plan["price_unit"]}" % (BigDecimal.new(addon_plan["price_cents"].to_s) / 100)
end
when /deprovision/i
resource_id = Settings.rest[1]
raise Addons::UserError, "Must supply resource id" unless resource_id
response = client.deprovision!(resource_id)
puts "Deprovisioned #{resource_id}"
puts response
when /provision/i
slug = Settings.rest[1]
raise Addons::UserError, "Must supply add-on:plan" unless slug
response = client.provision!(slug, :options => Settings[:options],
:consumer_id => Settings[:consumer_id])
puts "Provisioned #{slug}"
puts response
when /plan-change/i
resource_id = Settings.rest[1]
raise Addons::UserError, "Must supply resource id" unless resource_id
plan = Settings.rest[2]
raise Addons::UserError, "Must supply plan after resource id" unless plan
response = client.plan_change!(resource_id, plan)
puts "Plan Changed to #{plan}"
puts response
else
if command
puts "#{command} is not a valid command"
else
puts "Command must be one of: provision, deprovision, plan-change"
end
end
end
|