lib/cloudstack-cli/commands/region.rb in cloudstack-cli-1.4.1 vs lib/cloudstack-cli/commands/region.rb in cloudstack-cli-1.4.2
- old
+ new
@@ -1,20 +1,29 @@
class Region < CloudstackCli::Base
desc 'list', 'list regions'
+ option :format, default: "table",
+ enum: %w(table json yaml)
def list
regions = client.list_regions
if regions.size < 1
say "No regions found."
else
- table = [%w(Name, Endpoint)]
- regions.each do |region|
- table << [
- region['name'], region['endpoint']
- ]
+ case options[:format].to_sym
+ when :yaml
+ puts({regions: regions}.to_yaml)
+ when :json
+ puts JSON.pretty_generate(regions: regions)
+ else
+ table = [%w(Name, Endpoint)]
+ regions.each do |region|
+ table << [
+ region['name'], region['endpoint']
+ ]
+ end
+ print_table table
+ say "Total number of regions: #{regions.size}"
end
- print_table table
- say "Total number of regions: #{regions.size}"
end
end
-end
\ No newline at end of file
+end