Skip to content

Commit 0211fd4

Browse files
authored
Merge pull request #575 from danajp/fix-no-opt-boolean-arg-parsing
Fix --no-opt boolean parsing when followed by an argument
2 parents e3fce16 + ea5d283 commit 0211fd4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/thor/parser/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def parse_boolean(switch)
189189
shift
190190
false
191191
else
192-
true
192+
!no_or_skip?(switch)
193193
end
194194
else
195195
@switches.key?(switch) || !no_or_skip?(switch)

spec/parser/options_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,18 @@ def remaining
349349
expect(parse("--foo", "bar")).to eq("foo" => true)
350350
expect(@opt.remaining).to eq(%w(bar))
351351
end
352+
353+
it "doesn't eat the next part of the param with 'no-opt' variant" do
354+
create :foo => :boolean
355+
expect(parse("--no-foo", "bar")).to eq("foo" => false)
356+
expect(@opt.remaining).to eq(%w(bar))
357+
end
358+
359+
it "doesn't eat the next part of the param with 'skip-opt' variant" do
360+
create :foo => :boolean
361+
expect(parse("--skip-foo", "bar")).to eq("foo" => false)
362+
expect(@opt.remaining).to eq(%w(bar))
363+
end
352364
end
353365

354366
describe "with :hash type" do

0 commit comments

Comments
 (0)