lib/cloudstack-cli/commands/template.rb in cloudstack-cli-0.0.5 vs lib/cloudstack-cli/commands/template.rb in cloudstack-cli-0.1.0

- old
+ new

@@ -1,25 +1,23 @@ -class Template < Thor +class Template < CloudstackCli::Base - desc 'template list', 'list templates by type [featured|self|self-executable|executable|community]' + desc 'list', 'list templates by type [featured|self|self-executable|executable|community]' option :project def list(type='featured') - cs_cli = CloudstackCli::Helper.new(options[:config]) - - if options[:project] - project = cs_cli.projects.select { |p| p['name'] == options[:project] }.first - exit_now! "Project '#{options[:project]}' not found" unless project + project = find_project if options[:project] + unless %w(featured self self-executable executable community).include? type + say "unsupported template type '#{type}'", :red + exit 1 end - - exit_now! "unsupported template type '#{type}'" unless - %w(featured self self-executable executable community).include? type - templates = cs_cli.templates(type, project ? project['id'] : nil) + templates = client.list_templates(type, project ? project['id'] : nil) if templates.size < 1 puts "No templates found" else + table = [["Name", "Zone"]] templates.each do |template| - puts template['name'] + table << [template['name'], template['zonename']] end + print_table(table) end end end \ No newline at end of file