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