From b5d89bc9077d8f61913fa317876391e76c5880cf Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 21 Jan 2020 11:54:23 +1100 Subject: [PATCH] feat: suppport equals sign in can-i-deploy pacticipant selector parameters Fixes: https://github.com/pact-foundation/pact_broker-client/pull/55 --- .../client/cli/version_selector_options_parser.rb | 15 ++++++++++++++- .../cli/version_selector_options_parser_spec.rb | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/pact_broker/client/cli/version_selector_options_parser.rb b/lib/pact_broker/client/cli/version_selector_options_parser.rb index 68a7f0d7..1bac0859 100644 --- a/lib/pact_broker/client/cli/version_selector_options_parser.rb +++ b/lib/pact_broker/client/cli/version_selector_options_parser.rb @@ -1,11 +1,14 @@ +# frozen_string_literal: true + module PactBroker module Client module CLI class VersionSelectorOptionsParser + def self.call words selectors = [] previous_option = nil - words.each do | word | + split_equals(words).each do | word | case word when "--pacticipant", "-a" selectors << {} @@ -33,6 +36,16 @@ def self.call words end selectors end + + def self.split_equals(words) + words.flat_map do |word| + if word.start_with?("-") && word.include?("=") + word.split('=', 2) + else + word + end + end + end end end end diff --git a/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb b/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb index b3fa2619..0954776b 100644 --- a/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +++ b/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb @@ -39,6 +39,15 @@ module CLI ],[ ["--pacticipant", "Foo", "--all", "prod", "--pacticipant", "Bar"], [{ pacticipant: "Foo", tag: "prod"}, { pacticipant: "Bar" } ] + ],[ + ["--pacticipant=Foo", "--version=1.2.3"], + [{ pacticipant: "Foo", version: "1.2.3" } ] + ],[ + ["--pacticipant=Foo=Bar", "--version", "1.2.3"], + [{ pacticipant: "Foo=Bar", version: "1.2.3" } ] + ],[ + ["--pacticipant", "Foo=Bar", "--version", "1.2.3"], + [{ pacticipant: "Foo=Bar", version: "1.2.3" } ] ] ]