Class: CloudstackClient::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/cloudstack_client/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(given_args = ARGV, config = {}) ⇒ Object

rescue error globally



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cloudstack_client/cli.rb', line 37

def self.start(given_args=ARGV, config={})
  super
rescue => e
  error_class = e.class.name.split('::')
  if error_class.size == 2 && error_class.first == "CloudstackClient"
    puts "\e[31mERROR\e[0m: #{error_class.last} - #{e.message}"
    puts e.backtrace if ARGV.include? "--debug"
  else
    raise
  end
end

Instance Method Details

#consoleObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cloudstack_client/cli.rb', line 92

def console
  cs_client = client(options)

  print "cloudstack_client version #{CloudstackClient::VERSION}"
  puts " (CloudStack API version #{cs_client.api.api_version})"
  puts "  try: list_virtual_machines state: \"running\""

  ARGV.clear
  Ripl.config[:prompt] = "#{@config[:environment]} >> "
  Ripl.start binding: cs_client.instance_eval{ binding }
end

#list_apisObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cloudstack_client/cli.rb', line 64

def list_apis
  apis = client(no_api_methods: true).send_request('command' => 'listApis')
  apis.each do |command|
    command.delete("response") if options[:remove_response]
    if options[:remove_description]
      command.delete("description")
      command["params"].each {|param| param.delete("description")}
    end
  end

  print case options[:format]
  when "yaml"
    apis.to_yaml
  else
    options[:pretty_print] ? JSON.pretty_generate(apis) : JSON.generate(apis)
  end
end

#versionObject



50
51
52
# File 'lib/cloudstack_client/cli.rb', line 50

def version
  say "cloudstack_client version #{CloudstackClient::VERSION}"
end