Skip to content

Commit

Permalink
Merge pull request #575 from danajp/fix-no-opt-boolean-arg-parsing
Browse files Browse the repository at this point in the history
Fix --no-opt boolean parsing when followed by an argument
  • Loading branch information
rafaelfranca authored Aug 11, 2017
2 parents e3fce16 + ea5d283 commit 0211fd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/thor/parser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def parse_boolean(switch)
shift
false
else
true
!no_or_skip?(switch)
end
else
@switches.key?(switch) || !no_or_skip?(switch)
Expand Down
12 changes: 12 additions & 0 deletions spec/parser/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ def remaining
expect(parse("--foo", "bar")).to eq("foo" => true)
expect(@opt.remaining).to eq(%w(bar))
end

it "doesn't eat the next part of the param with 'no-opt' variant" do
create :foo => :boolean
expect(parse("--no-foo", "bar")).to eq("foo" => false)
expect(@opt.remaining).to eq(%w(bar))
end

it "doesn't eat the next part of the param with 'skip-opt' variant" do
create :foo => :boolean
expect(parse("--skip-foo", "bar")).to eq("foo" => false)
expect(@opt.remaining).to eq(%w(bar))
end
end

describe "with :hash type" do
Expand Down

0 comments on commit 0211fd4

Please sign in to comment.