diff options
author | Sutou Kouhei <kou@clear-code.com> | 2019-06-24 19:01:13 +0900 |
---|---|---|
committer | Sutou Kouhei <kou@clear-code.com> | 2019-06-29 06:18:09 +0900 |
commit | c026ee99247c33130addc01d1399e71b14879f38 (patch) | |
tree | b50c90fbcefadd3d2e3b73792eba68ac37bd9617 /lib | |
parent | aa233ababf00cd32f46a278ca030d5c40281e7c1 (diff) | |
download | slop-c026ee99247c33130addc01d1399e71b14879f38.tar.gz |
Fix a bug that flag value is processed as flag
If flag value starts with "-", unknown option error is raised.
The current flag value check is "orig_arg == opt.value.to_s". There
are some objects such as Regexp and Time that input value and its #to_s
aren't same.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/slop/parser.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb index 27e1c50..c6462ea 100644 --- a/lib/slop/parser.rb +++ b/lib/slop/parser.rb @@ -64,7 +64,7 @@ module Slop if opt.expects_argument? # if we consumed the argument, remove the next pair - if orig_arg == opt.value.to_s + if consume_next_argument?(orig_flag) pairs.delete_at(idx + 1) end @@ -106,6 +106,13 @@ module Slop private + def consume_next_argument?(flag) + return false if flag.include?("=") + return true if flag.start_with?("--") + return true if /\A-[a-zA-Z]\z/ === flag + false + end + # We've found an option, process and return it def process(option, arg) option.ensure_call(arg) |