summaryrefslogtreecommitdiff
path: root/lib/slop/parser.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/slop/parser.rb')
-rw-r--r--lib/slop/parser.rb27
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index 0b33d55..142540a 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -111,13 +111,7 @@ module Slop
elsif flag.start_with?("--no-") && option = matching_option(flag.sub("no-", ""))
process(option, false)
elsif flag =~ /\A-[^-]{2,}/
- # try and process as a set of grouped short flags. drop(1) removes
- # the prefixed -, then we add them back to each flag separately.
- flags = flag.split("").drop(1).map { |f| "-#{f}" }
- last = flags.pop
-
- flags.each { |f| try_process(f, nil) }
- try_process(last, arg) # send the argument to the last flag
+ try_process_smashed_arg(flag) || try_process_grouped_flags(flag, arg)
else
if flag.start_with?("-") && !suppress_errors?
raise UnknownOption.new("unknown option `#{flag}'", "#{flag}")
@@ -125,6 +119,25 @@ module Slop
end
end
+ # try and process a flag with a "smashed" argument, e.g.
+ # -nFoo or -i5
+ def try_process_smashed_arg(flag)
+ option = matching_option(flag[0, 2])
+ if option && option.expects_argument?
+ process(option, flag[2..-1])
+ end
+ end
+
+ # try and process as a set of grouped short flags. drop(1) removes
+ # the prefixed -, then we add them back to each flag separately.
+ def try_process_grouped_flags(flag, arg)
+ flags = flag.split("").drop(1).map { |f| "-#{f}" }
+ last = flags.pop
+
+ flags.each { |f| try_process(f, nil) }
+ try_process(last, arg) # send the argument to the last flag
+ end
+
def suppress_errors?
config[:suppress_errors]
end