Skip to content

Commit

Permalink
Merge d5ff65e into ff37cba
Browse files Browse the repository at this point in the history
  • Loading branch information
tsontario committed Feb 27, 2020
2 parents ff37cba + d5ff65e commit 52602a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
c
@opt.instance_variable_get(:@switches)["--foo"].default
@opt.instance_variable_get(:@switches)["--foo"]
@opt.instance_variable_get(:@switches)
@opt.instance_variable_get(:@switches).default
c
@opt.instance_variable_get(:@switches).default
@opt.instance_variable_get(:@switches)
@opt.instance_variable_get(:@switces)
@opt.switches
@opt
exit
@opt.switches
@opt.instance_variables
@opt.assigns
@opt
@opt.switch
@opt.switches
@opt
exit
self
foo
:foo
7 changes: 6 additions & 1 deletion lib/thor/parser/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def initialize(arguments = [])

arguments.each do |argument|
if !argument.default.nil?
@assigns[argument.human_name] = argument.default
begin
@assigns[argument.human_name] = argument.default.dup
rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4
@assigns[argument.human_name] = argument.default
next
end
elsif argument.required?
@non_assigned_required << argument
end
Expand Down
7 changes: 3 additions & 4 deletions spec/parser/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,10 @@ def remaining
"Expected '--fruit' to be one of #{enum.join(', ')}; got orange")
end

it "allows multiple values if repeatable is specified" do
create :foo => Thor::Option.new("foo", :type => :string, :repeatable => true)

it "can does not erroneously mutate defaults" do
create :foo => Thor::Option.new("foo", :type => :string, :repeatable => true, :required => false, :default => [])
expect(parse("--foo=bar", "--foo", "12")["foo"]).to eq(["bar", "12"])
expect(parse("--foo", "13", "--foo", "14")["foo"]).to eq(["bar", "12", "13", "14"])
expect(@opt.instance_variable_get(:@switches)["--foo"].default).to eq([])
end
end

Expand Down

0 comments on commit 52602a0

Please sign in to comment.