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

- old
+ new

@@ -1,23 +1,32 @@ class Job < CloudstackCli::Base desc 'list', 'list async jobs' + option :format, default: "table", + enum: %w(table json yaml) def list jobs = client.list_async_jobs if jobs.size < 1 say "No jobs found." else - table = [%w(Command Created Status ID User-ID)] - jobs.each do |job| - table << [ - job['cmd'].split('.')[-1], - job['created'], - job['jobstatus'], - job['jobid'], - job['userid'] - ] + case options[:format].to_sym + when :yaml + puts({jobs: jobs}.to_yaml) + when :json + puts JSON.pretty_generate(jobs: jobs) + else + table = [%w(Command Created Status ID User-ID)] + jobs.each do |job| + table << [ + job['cmd'].split('.')[-1], + job['created'], + job['jobstatus'], + job['jobid'], + job['userid'] + ] + end + print_table table end - print_table table end end desc 'query ID', 'query async job' def query(id)