simplify outputting in client
This commit is contained in:
parent
ef26dc19e4
commit
75ffceaa7d
@ -4,17 +4,13 @@ module Outputtable
|
||||
@list || @show
|
||||
end
|
||||
|
||||
def additional_output_options
|
||||
{}
|
||||
end
|
||||
|
||||
def outputter
|
||||
raise 'You should use "output_with" method to define outputter' unless defined?(outputter_class)
|
||||
@outputter ||= outputter_class.new(data_to_output, options, additional_output_options)
|
||||
@outputter ||= outputter_class.new(data_to_output, options.merge(current_command: current_command))
|
||||
end
|
||||
|
||||
def output(preferred_format=nil)
|
||||
outputter.output(preferred_format)
|
||||
def output(options={})
|
||||
outputter.output(options)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ class Project < Handler
|
||||
when "servers"
|
||||
self.options = @options_parser.servers_options
|
||||
servers_handler @options_parser.args
|
||||
output
|
||||
output(output_type: :servers)
|
||||
when "set"
|
||||
case ARGV[2]
|
||||
when "run_list"
|
||||
@ -61,7 +61,7 @@ class Project < Handler
|
||||
when "show"
|
||||
self.options = @options_parser.show_options
|
||||
show_handler @options_parser.args
|
||||
output
|
||||
output(output_type: :show)
|
||||
when "update"
|
||||
self.options = @options_parser.update_options
|
||||
update_handler @options_parser.args
|
||||
@ -80,7 +80,7 @@ class Project < Handler
|
||||
when "test"
|
||||
self.options = @options_parser.test_options
|
||||
test_handler @options_parser.args
|
||||
output
|
||||
output(output_type: :test)
|
||||
else
|
||||
@options_parser.invalid_command
|
||||
end
|
||||
@ -422,14 +422,4 @@ protected
|
||||
@list || @show || @servers || @test
|
||||
end
|
||||
|
||||
def additional_output_options
|
||||
output_type = case ARGV[1]
|
||||
when 'servers', 'test', 'show'
|
||||
ARGV[1].to_sym
|
||||
else
|
||||
:list
|
||||
end
|
||||
{output_type: output_type}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -30,7 +30,7 @@ class Stack < Handler
|
||||
output
|
||||
when :resources
|
||||
resources_handler
|
||||
output('json')
|
||||
output(resource: @args[3])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -7,20 +7,13 @@ module Output
|
||||
|
||||
attr_reader :options
|
||||
|
||||
# QUESTION:
|
||||
# Earlier I use additional parameter "output_type". Now I use
|
||||
# detecting output_type from data_to_output.class:
|
||||
# Array means we are outputting list command,
|
||||
# Hash or something other - we are outputting show command.
|
||||
# Is this OK?
|
||||
|
||||
def initialize(data_to_output, command_line_options={}, additional_options={})
|
||||
@data, @options, @additional_options = data_to_output, command_line_options, additional_options
|
||||
def initialize(data_to_output, options={})
|
||||
@data, @options = data_to_output, options
|
||||
end
|
||||
|
||||
def output(format = nil)
|
||||
format ||= options[:format]
|
||||
case format
|
||||
def output(preferred_options)
|
||||
@options = @options.merge(preferred_options)
|
||||
case options[:format]
|
||||
when CommonOptions::TABLE_FORMAT
|
||||
table
|
||||
when CommonOptions::JSON_FORMAT
|
||||
|
||||
@ -9,15 +9,12 @@ module Output
|
||||
def table
|
||||
title = nil
|
||||
with_separator = false
|
||||
headers, rows = case @additional_options[:output_type]
|
||||
when :list
|
||||
title = I18n.t("output.title.project.list")
|
||||
create_list(@data)
|
||||
headers, rows = case options[:output_type]
|
||||
when :show
|
||||
title = I18n.t("output.title.project.show", :name => @data["name"])
|
||||
with_separator = true
|
||||
create_show(@data)
|
||||
when :server
|
||||
when :servers
|
||||
title = ARGV[2]
|
||||
title += " " + ARGV[3] unless ARGV[3].nil?
|
||||
title = I18n.t("output.title.project.servers", :title => title)
|
||||
@ -25,6 +22,9 @@ module Output
|
||||
when :test
|
||||
title = I18n.t("output.title.project.test", :project => ARGV[2], :env => ARGV[3])
|
||||
create_test(@data)
|
||||
else
|
||||
title = I18n.t("output.title.project.list")
|
||||
create_list(@data)
|
||||
end
|
||||
create_table(headers, rows, title, with_num?, with_separator)
|
||||
end
|
||||
|
||||
@ -6,6 +6,11 @@ module Output
|
||||
include Concerns::HasProvider
|
||||
|
||||
def table
|
||||
if options[:current_command] == :resources
|
||||
if options[:resource].nil?
|
||||
headers, rows = create_servers_list
|
||||
end
|
||||
else
|
||||
if outputting_list?
|
||||
title = I18n.t("output.title.stack.list")
|
||||
headers, rows = create_list
|
||||
@ -14,6 +19,7 @@ module Output
|
||||
title = I18n.t("output.title.stack.show", id: @data["id"])
|
||||
headers, rows = create_show
|
||||
end
|
||||
end
|
||||
create_table(headers, rows, title, with_num?)
|
||||
end
|
||||
|
||||
@ -41,5 +47,13 @@ module Output
|
||||
headers_and_rows([@data], %w(id deploy_env stack_template cloud_stack_id stack_status))
|
||||
end
|
||||
|
||||
def create_servers_list
|
||||
headers = ['Logical id', 'Physical id']
|
||||
rows = @data.map do |resource|
|
||||
[resource['resource_name'], resource['physical_resource_id']]
|
||||
end
|
||||
[headers, rows]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user