Permalink
Browse files

Allow passing options as arguments after '--'.

  • Loading branch information...
1 parent 8897e57 commit 3ba11bcfc9c072adef5c39a069845ff0534313db @eventualbuddha eventualbuddha committed Oct 2, 2012
Showing with 16 additions and 0 deletions.
  1. +6 −0 lib/thor/parser/options.rb
  2. +10 −0 spec/parser/options_spec.rb
@@ -57,6 +57,12 @@ def parse(args)
match, is_switch = current_is_switch?
shifted = shift
+ if shifted == '--'
+ @extra += @pile
+ @pile.clear
+ break
+ end
+
if is_switch
case shifted
when SHORT_SQ_RE
@@ -18,6 +18,10 @@ def check_unknown!
@opt.check_unknown!
end
+ def remaining
+ @opt.remaining
+ end
+
describe "#to_switches" do
it "turns true values into a flag" do
Thor::Options.to_switches(:color => true).should == "--color"
@@ -133,6 +137,12 @@ def check_unknown!
parse("--baz_foo", "foo bar")["baz_foo"].should == "foo bar"
end
+ it "interprets everything after -- as args instead of options" do
+ create(:foo => :string, :bar => :required)
+ parse(%w[--bar abc moo -- --foo def -a]).should == {"bar" => "abc"}
+ remaining.should == %w[moo --foo def -a]
+ end
+
describe "with no input" do
it "and no switches returns an empty hash" do
create({})

0 comments on commit 3ba11bc

Please sign in to comment.