Skip to content

Commit

Permalink
fix: stop long values in columns from being truncated
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 30, 2021
1 parent fc8ce3b commit 18063fd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
12 changes: 6 additions & 6 deletions lib/pact_broker/client/cli/environment_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,42 @@ def self.shared_environment_options(name_required: false)
shared_environment_options(name_required: true)
shared_authentication_options
def create_environment
execute_command(params_from_options(ENVIRONMENT_PARAM_NAMES), "CreateEnvironment")
execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES), "CreateEnvironment")
end

desc "update-environment", "Update an environment resource in the Pact Broker."
method_option :uuid, required: true, desc: "The UUID of the environment to update"
shared_environment_options(name_required: false)
shared_authentication_options
def update_environment
execute_command(params_from_options(ENVIRONMENT_PARAM_NAMES + [:uuid]), "UpdateEnvironment")
execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES + [:uuid]), "UpdateEnvironment")
end

desc "describe-environment", "Describe an environment"
method_option :uuid, required: true, desc: "The UUID of the environment to describe"
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
shared_authentication_options
def describe_environment
execute_command(params_from_options([:uuid]), "DescribeEnvironment")
execute_environment_command(params_from_options([:uuid]), "DescribeEnvironment")
end

desc "list-environments", "List environment"
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
shared_authentication_options
def list_environments
execute_command({}, "ListEnvironments")
execute_environment_command({}, "ListEnvironments")
end

desc "delete-environment", "Delete an environment"
method_option :uuid, required: true, desc: "The UUID of the environment to delete"
method_option :output, aliases: "-o", desc: "json or text", default: 'text'
shared_authentication_options
def delete_environment
execute_command(params_from_options([:uuid]), "DeleteEnvironment")
execute_environment_command(params_from_options([:uuid]), "DeleteEnvironment")
end

no_commands do
def execute_command(params, command_class_name)
def execute_environment_command(params, command_class_name)
require 'pact_broker/client/environments'
command_options = { verbose: options.verbose, output: options.output }
result = PactBroker::Client::Environments.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
Expand Down
6 changes: 3 additions & 3 deletions lib/pact_broker/client/cli/pacticipant_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ def self.included(thor)

def create_or_update_pacticipant(*required_but_ignored)
raise ::Thor::RequiredArgumentMissingError, "Pacticipant name cannot be blank" if options.name.strip.size == 0
execute_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'Create')
execute_pacticipant_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'Create')
end

desc 'list-pacticipants', 'List pacticipants'
output_option_json_or_text
shared_authentication_options
verbose_option
def list_pacticipants
execute_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'List')
execute_pacticipant_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'List')
end

no_commands do
def execute_command(params, command_class_name)
def execute_pacticipant_command(params, command_class_name)
require 'pact_broker/client/pacticipants'
command_options = { verbose: options.verbose, output: options.output }
result = PactBroker::Client::Pacticipants2.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
Expand Down
34 changes: 21 additions & 13 deletions lib/pact_broker/client/matrix/text_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,17 @@ class TextFormatter

Line = Struct.new(:consumer, :consumer_version, :provider, :provider_version, :success, :ref, :ignored)

TP_OPTIONS = [
{ consumer: {} },
{ consumer_version: {display_name: 'C.VERSION'} },
{ provider: {} },
{ provider_version: {display_name: 'P.VERSION'} },
{ success: {display_name: 'SUCCESS?'} },
{ ref: { display_name: 'RESULT#' } }
]

def self.call(matrix)
tp_options = TP_OPTIONS.dup
matrix_rows = matrix[:matrix]
return "" if matrix_rows.size == 0
data = prepare_data(matrix_rows)
printer = TablePrint::Printer.new(data, tp_options(data))
printer.table_print + verification_result_urls_text(matrix)
end

def self.prepare_data(matrix_rows)
verification_result_number = 0
data = matrix_rows.each_with_index.collect do | line |
matrix_rows.each_with_index.collect do | line |
has_verification_result_url = lookup(line, nil, :verificationResult, :_links, :self, :href)
if has_verification_result_url
verification_result_number += 1
Expand All @@ -40,9 +36,17 @@ def self.call(matrix)
lookup(line, nil, :ignored)
)
end
end

printer = TablePrint::Printer.new(data, tp_options)
printer.table_print + verification_result_urls_text(matrix)
def self.tp_options(data)
[
{ consumer: { width: max_width(data, :consumer, 'CONSUMER') } },
{ consumer_version: { display_name: 'C.VERSION', width: max_width(data, :consumer_version, 'C.VERSION') } },
{ provider: { width: max_width(data, :provider, 'PROVIDER') } },
{ provider_version: { display_name: 'P.VERSION', width: max_width(data, :provider_version, 'P.VERSION') } },
{ success: { display_name: 'SUCCESS?' } },
{ ref: { display_name: 'RESULT#' } }
]
end

def self.lookup line, default, *keys
Expand Down Expand Up @@ -75,6 +79,10 @@ def self.verification_result_urls_text(matrix)
text
end
end

def self.max_width(data, column, title)
(data.collect{ |row| row.send(column) } + [title]).compact.collect(&:size).max
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/pact_broker/client/pacticipants.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# New code
Dir.glob(File.join(__FILE__.gsub(".rb", "/**/*.rb"))).sort.each do | path |
puts path
require path
end

Expand Down
17 changes: 10 additions & 7 deletions lib/pact_broker/client/pacticipants/text_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ def self.call(pacticipants)
OpenStruct.new({ uuid: "" }.merge(pacticipant).merge(url: pacticipant["_links"]["self"]["href"]))
end.sort_by{ | pacticipant | pacticipant.name.downcase }

uuid_width = max_width(data, :uuid)
name_width = max_width(data, :name)
display_name_width = max_width(data, :display_name)
TablePrint::Printer.new(data, tp_options(data)).table_print
end

def self.tp_options(data)
uuid_width = max_width(data, :uuid, "")
name_width = max_width(data, :name, "NAME")
display_name_width = max_width(data, :displayName, "DISPLAY NAME")

tp_options = [
{ name: { width: name_width} },
Expand All @@ -25,12 +29,11 @@ def self.call(pacticipants)
if uuid_width > 0
tp_options.unshift({ uuid: { width: uuid_width } })
end

TablePrint::Printer.new(data, tp_options).table_print
tp_options
end

def self.max_width(data, column)
data.collect{ |row| row.send(column) }.compact.collect(&:size).max
def self.max_width(data, column, title)
(data.collect{ |row| row.send(column) } + [title]).compact.collect(&:size).max
end
end
end
Expand Down

0 comments on commit 18063fd

Please sign in to comment.