lib/cloudstack-cli/cli.rb in cloudstack-cli-0.15.1 vs lib/cloudstack-cli/cli.rb in cloudstack-cli-1.0.0.rc1
- old
+ new
@@ -13,11 +13,12 @@
aliases: '-e',
desc: 'Environment to use'
class_option :debug,
desc: 'Enable debug output',
- type: :boolean
+ type: :boolean,
+ default: false
desc "version", "Print cloudstack-cli version number"
def version
say "cloudstack-cli version #{CloudstackCli::VERSION}"
say " (cloudstack_client version #{CloudstackClient::VERSION})"
@@ -43,18 +44,27 @@
end
puts File.read shell_script
end
desc "command COMMAND [arg1=val1 arg2=val2...]", "Run a custom api command"
+ option :format, default: 'json',
+ enum: %w(json yaml), desc: "output format"
+ option :pretty_print, default: true, type: :boolean,
+ desc: "pretty print json output"
def command(command, *args)
params = {'command' => command}
args.each do |arg|
arg = arg.split('=')
params[arg[0]] = arg[1]
end
data = client.send_request(params)
- puts JSON.pretty_generate(data)
+ output = if options[:format] == 'json'
+ options[:pretty_print] ? JSON.pretty_generate(data) : data.to_json
+ else
+ data.to_yaml
+ end
+ puts output
end
# require subcommands
Dir[File.dirname(__FILE__) + '/commands/*.rb'].each do |command|
require command
@@ -77,11 +87,13 @@
subcommand :host, Host
desc "project SUBCOMMAND ...ARGS", "Manage servers"
subcommand :project, Project
- desc "server SUBCOMMAND ...ARGS", "Manage servers"
- subcommand :server, Server
+ desc "virtual_machine SUBCOMMAND ...ARGS", "Manage virtual machines"
+ subcommand :virtual_machine, VirtualMachine
+ map 'vm' => :virtual_machine
+ map 'server' => :virtual_machine
desc "compute_offer SUBCOMMAND ...ARGS", "Manage offerings"
subcommand :compute_offer, ComputeOffer
desc "disk_offer SUBCOMMAND ...ARGS", "Manage disk offerings"