summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/slop/parser.rb20
-rw-r--r--test/parser_test.rb3
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index 142540a..2b20d36 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -36,6 +36,9 @@ module Slop
def parse(strings)
reset # reset before every parse
+ # ignore everything after "--"
+ strings, ignored_args = partition(strings)
+
pairs = strings.each_cons(2).to_a
# this ensures we still support the last string being a flag,
# otherwise it'll only be used as an argument.
@@ -47,12 +50,6 @@ module Slop
flag, arg = pair
break if !flag
- # ignore everything after '--', flag or not
- if flag == '--'
- arguments.delete(flag)
- break
- end
-
# support `foo=bar`
orig_flag = flag.dup
orig_arg = arg
@@ -81,6 +78,8 @@ module Slop
end
end
+ @arguments += ignored_args
+
Result.new(self).tap do |result|
used_options.each { |o| o.finish(result) }
end
@@ -145,5 +144,14 @@ module Slop
def matching_option(flag)
options.find { |o| o.flags.include?(flag) }
end
+
+ private def partition(strings)
+ if strings.include?("--")
+ partition_idx = strings.index("--")
+ [strings[0..partition_idx-1], strings[partition_idx+1..-1]]
+ else
+ [strings, []]
+ end
+ end
end
end
diff --git a/test/parser_test.rb b/test/parser_test.rb
index fa372cf..dcc3661 100644
--- a/test/parser_test.rb
+++ b/test/parser_test.rb
@@ -11,8 +11,9 @@ describe Slop::Parser do
end
it "ignores everything after --" do
- @parser.parse %w(-v -- --name lee)
+ @parser.parse %w(-v -- -v --name lee)
assert_equal [@verbose], @parser.used_options
+ assert_equal ["-v", "--name", "lee"], @parser.arguments
end
it "parses flag=argument" do