summaryrefslogtreecommitdiff
path: root/lib/slop/parser.rb
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2014-11-19 16:54:45 +0000
committerLee Jarvis <ljjarvis@gmail.com>2014-11-19 16:57:05 +0000
commitb2a7405975debde3d0344d348bc1d56aff37bdc2 (patch)
treec417a6914bfe849304ecb85a9db646a1dd3cfb3f /lib/slop/parser.rb
parent1264729e19ee69b8ff04c3b6c2ab4650e34b4067 (diff)
downloadslop-b2a7405975debde3d0344d348bc1d56aff37bdc2.tar.gz
Handle short grouped flags
Diffstat (limited to 'lib/slop/parser.rb')
-rw-r--r--lib/slop/parser.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index 12c067d..984cf5d 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -41,14 +41,23 @@ module Slop
private
+ # We've found an option, process it
+ def process(option, arg)
+ used_options << option
+ option.ensure_call(arg)
+ end
+
+ # Try and find an option to process
def try_process(flag, arg)
if option = matching_option(flag)
- used_options << option
- option.ensure_call(arg)
- else
- if flag =~ /-[^-]/
- p flag.split("")[1..-1]
- end
+ process(option, arg)
+ elsif flag =~ /-[^-]/ && flag.size > 2
+ # try and process as a set of grouped short flags
+ 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
end