Skip to content

Commit

Permalink
fix: correctly handle multiple parameters specified in the format --n…
Browse files Browse the repository at this point in the history
…ame=value
  • Loading branch information
bethesque committed Feb 19, 2020
1 parent ca1c27b commit 946001b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/pact_broker/client/cli/custom_thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,31 @@ def self.known_first_arguments
def self.turn_muliple_tag_options_into_array argv
new_argv = []
opt_name = nil
argv.each_with_index do | arg, i |
if arg.start_with?('-')
opt_name = arg
existing = new_argv.find { | a | a.first == opt_name }
if !existing
new_argv << [arg]
argv.each_with_index do | word, i |
if word.start_with?('-')
if word.include?('=')
opt_name, opt_value = word.split('=', 2)

existing = new_argv.find { | a | a.first == opt_name }
if existing
existing << opt_value
else
new_argv << [opt_name, opt_value]
end
else
opt_name = word
existing = new_argv.find { | a | a.first == opt_name }
if !existing
new_argv << [word]
end
end
else
if opt_name
existing = new_argv.find { | a | a.first == opt_name }
existing << arg
existing << word
opt_name = nil
else
new_argv << [arg]
new_argv << [word]
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/pact_broker/client/cli/custom_thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def test_without_parameters
expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
end

it "turns '--tag=foo --tag=bar' into '--tag foo bar'" do
input = %w{--ignore this --tag=foo --tag=bar --wiffle --that}
output = %w{--ignore this --tag foo bar --wiffle --that }
expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq output
end

it "doesn't change anything when there are no duplicate options" do
input = %w{--ignore this --taggy foo --blah bar --wiffle --that}
expect(TestThor.turn_muliple_tag_options_into_array(input)).to eq input
Expand Down

0 comments on commit 946001b

Please sign in to comment.