summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/slop/parser.rb20
1 files changed, 14 insertions, 6 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