class Mocloud::Commands::Stacks
Public Instance Methods
description()
click to toggle source
# File lib/mocloud/commands/stacks.rb, line 15 def description "List your stacks" end
run()
click to toggle source
# File lib/mocloud/commands/stacks.rb, line 19 def run Trollop::options do banner <<-ENDOFHELP Usage: mobingi stacks [options]" Shows the stacks on your Mobingi account ENDOFHELP end creds = Mocloud::Utils::Credentials.new user = creds.read_credentials() token = creds.make_token(0) api = Mocloud::API.new res = api.get ("/v1/describe/#{user['uid']}/stack") Mocloud::Utils.handle_error(res, "Show stacks failed") data = JSON.parse(res[:body]) output = data.map do |x| { :id => x["stack_id"]["S"], :nick => x["nickname"]["S"], :instance_count => x["instances"]["L"].length } end puts "List of stacks:" rows = [] output.each do |x| rows << [x[:nick], x[:id], x[:instance_count]] end table = Terminal::Table.new :headings => ['Name', 'ID', 'Instances'], :rows => rows puts table end