lib/cloudstack-cli/commands/project.rb in cloudstack-cli-1.4.1 vs lib/cloudstack-cli/commands/project.rb in cloudstack-cli-1.4.2

- old
+ new

@@ -12,28 +12,37 @@ end end desc "list", "list projects" option :domain, desc: "List only resources belonging to the domain specified" + option :format, default: "table", + enum: %w(table json yaml) def list resolve_domain projects = client.list_projects(options.merge listall: true) if projects.size < 1 puts "No projects found." else - table = [%w(Name Displaytext VMs CPU Memory Domain)] - projects.each do |project| - table << [ - project['name'], - project['displaytext'], - project['vmtotal'], - project['cputotal'], - project['memorytotal'] / 1024, - project['domain'] - ] + case options[:format].to_sym + when :yaml + puts({projects: projects}.to_yaml) + when :json + puts JSON.pretty_generate(projects: projects) + else + table = [%w(Name Displaytext VMs CPU Memory Domain)] + projects.each do |project| + table << [ + project['name'], + project['displaytext'], + project['vmtotal'], + project['cputotal'], + project['memorytotal'] / 1024, + project['domain'] + ] + end + print_table(table) + say "Total number of projects: #{projects.count}" end - print_table(table) - say "Total number of projects: #{projects.count}" end end desc "list_accounts PROJECT_NAME", "show accounts belonging to a project" def list_accounts(name)