summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNaoki Mizuno <nigorojr@gmail.com>2015-09-08 15:40:07 -0400
committerNaoki Mizuno <nigorojr@gmail.com>2015-09-08 15:40:07 -0400
commit3df82ee30f7330d8137001c39737c5d7ebf6fcab (patch)
treec18a13bad73e41a4b6b5b4abc85b2f9a30df72fa /lib
parentebe678b1639654604b3e54b08ca710c38682b83e (diff)
downloadslop-3df82ee30f7330d8137001c39737c5d7ebf6fcab.tar.gz
Fix bug regarding --foo=bar style options
This fixes the bug introduced in ebe678b1639654604b3e54b08ca710c38682b83e where the argument after a flag is naively deleted. For example, with --foo=bar baz , both `--foo=bar' and `baz' are deleted when only `--foo=bar' should be deleted.
Diffstat (limited to 'lib')
-rw-r--r--lib/slop/parser.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index 553c2ff..ea1869e 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -53,6 +53,7 @@ module Slop
end
# support `foo=bar`
+ orig_flag = flag.dup
if flag.include?("=")
flag, arg = flag.split("=")
end
@@ -60,13 +61,15 @@ module Slop
if opt = try_process(flag, arg)
# since the option was parsed, we remove it from our
# arguments (plus the arg if necessary)
- # delete argument first so that it doesn't mess up the index
+ # delete argument first while we can find its index.
if opt.expects_argument?
arguments.each_with_index do |argument, i|
- arguments.delete_at(i + 1) if argument == flag
+ if argument == orig_flag && !orig_flag.include?("=")
+ arguments.delete_at(i + 1)
+ end
end
end
- arguments.delete(flag)
+ arguments.delete(orig_flag)
end
end