Skip to content

Commit

Permalink
Repeatable hash type flags bugfix.
Browse files Browse the repository at this point in the history
They treated like every other type now. Instead of merging each key/val
into a hash, each flag is treated like it's own hash that should be put
into an array.

fixes rails#768
  • Loading branch information
patrick-motard committed Jan 17, 2022
1 parent 6ba7901 commit f33af3b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/thor/parser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ def check_unknown!
protected

def assign_result!(option, result)
if option.repeatable && option.type == :hash
(@assigns[option.human_name] ||= {}).merge!(result)
elsif option.repeatable
if option.repeatable
(@assigns[option.human_name] ||= []) << result
else
@assigns[option.human_name] = result
Expand Down
2 changes: 1 addition & 1 deletion spec/parser/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def remaining

it "allows multiple values if repeatable is specified" do
create :attributes => Thor::Option.new("attributes", :type => :hash, :repeatable => true)
expect(parse("--attributes", "name:one", "foo:1", "--attributes", "name:two", "bar:2")["attributes"]).to eq({"name"=>"two", "foo"=>"1", "bar" => "2"})
expect(parse("--attributes", "name:one", "foo:1", "--attributes", "name:two", "bar:2")["attributes"]).to eq([{"name"=>"one", "foo"=>"1"}, {"name"=>"two", "bar" => "2"}])
end
end

Expand Down

0 comments on commit f33af3b

Please sign in to comment.