diff --git a/lib/pact_broker/client/cli/pacticipant_commands.rb b/lib/pact_broker/client/cli/pacticipant_commands.rb index 0246059f..9d273087 100644 --- a/lib/pact_broker/client/cli/pacticipant_commands.rb +++ b/lib/pact_broker/client/cli/pacticipant_commands.rb @@ -27,6 +27,15 @@ def list_pacticipants execute_pacticipant_command(params_from_options(PACTICIPANT_PARAM_NAMES), 'List') end + desc 'describe-pacticipant', "Describe a pacticipant" + method_option :name, type: :string, required: true, desc: "Pacticipant name" + output_option_json_or_text + shared_authentication_options + verbose_option + def describe_pacticipant + execute_pacticipant_command({ name: options.name }, 'Describe') + end + no_commands do def execute_pacticipant_command(params, command_class_name) require 'pact_broker/client/pacticipants' diff --git a/lib/pact_broker/client/describe_text_formatter.rb b/lib/pact_broker/client/describe_text_formatter.rb new file mode 100644 index 00000000..464b2118 --- /dev/null +++ b/lib/pact_broker/client/describe_text_formatter.rb @@ -0,0 +1,23 @@ +require 'yaml' +require 'pact_broker/client/generate_display_name' + +module PactBroker + module Client + class DescribeTextFormatter + extend GenerateDisplayName + + def self.call(properties) + YAML.dump(displayify_keys(properties)).gsub("---\n", "") + end + + def self.displayify_keys(thing) + case thing + when Hash then thing.each_with_object({}) { | (key, value), new_hash | new_hash[generate_display_name(key)] = displayify_keys(value) } + when Array then thing.collect{ | value | displayify_keys(value) } + else + thing + end + end + end + end +end \ No newline at end of file diff --git a/lib/pact_broker/client/environments/describe_environment.rb b/lib/pact_broker/client/environments/describe_environment.rb index 53979758..0b40bf09 100644 --- a/lib/pact_broker/client/environments/describe_environment.rb +++ b/lib/pact_broker/client/environments/describe_environment.rb @@ -1,12 +1,10 @@ require 'pact_broker/client/environments/environment_command' -require 'pact_broker/client/generate_display_name' -require 'yaml' +require 'pact_broker/client/describe_text_formatter' module PactBroker module Client module Environments class DescribeEnvironment < PactBroker::Client::Environments::EnvironmentCommand - include PactBroker::Client::GenerateDisplayName private def do_call @@ -18,16 +16,8 @@ def result_message if json_output? existing_environment_resource.response.raw_body else - YAML.dump(displayify_keys(existing_environment_resource.response.body.except("_links"))).gsub("---\n", "") - end - end - - def displayify_keys(thing) - case thing - when Hash then thing.each_with_object({}) { | (key, value), new_hash | new_hash[generate_display_name(key)] = displayify_keys(value) } - when Array then thing.collect{ | value | displayify_keys(value) } - else - thing + properties = existing_environment_resource.response.body.except("_links", "_embedded") + PactBroker::Client::DescribeTextFormatter.call(properties) end end end diff --git a/lib/pact_broker/client/pacticipants/describe.rb b/lib/pact_broker/client/pacticipants/describe.rb new file mode 100644 index 00000000..14ab2123 --- /dev/null +++ b/lib/pact_broker/client/pacticipants/describe.rb @@ -0,0 +1,33 @@ +require 'pact_broker/client/base_command' +require 'pact_broker/client/describe_text_formatter' + +module PactBroker + module Client + module Pacticipants2 + class Describe < PactBroker::Client::BaseCommand + + private + + def do_call + PactBroker::Client::CommandResult.new(true, result_message) + end + + def pacticipant_entity + @pacticipant_entity ||= index_resource._link('pb:pacticipant').expand('pacticipant' => params[:name]).get! + end + + def result_message + if json_output? + pacticipant_entity.response.raw_body + else + properties = pacticipant_entity.response.body.except("_links", "_embedded") + if pacticipant_entity._embedded["labels"] && pacticipant_entity._embedded["labels"].any? + properties["labels"] = pacticipant_entity._embedded["labels"] + end + PactBroker::Client::DescribeTextFormatter.call(properties) + end + end + end + end + end +end