diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 16:24:47 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 16:38:06 +0000 |
commit | 1264729e19ee69b8ff04c3b6c2ab4650e34b4067 (patch) | |
tree | e56cec2b92863001c42e1cfb11a0f2b0e3125191 /lib/slop/parser.rb | |
parent | 2a312300798d1da4aa666a0888f8a94a5ee5f245 (diff) | |
download | slop-1264729e19ee69b8ff04c3b6c2ab4650e34b4067.tar.gz |
Support flag=arg
Diffstat (limited to 'lib/slop/parser.rb')
-rw-r--r-- | lib/slop/parser.rb | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb index ef31ee1..12c067d 100644 --- a/lib/slop/parser.rb +++ b/lib/slop/parser.rb @@ -21,13 +21,13 @@ module Slop pairs << [strings.last, nil] pairs.each do |flag, arg| - break if flag == '--' + break if !flag || flag == '--' - if option = matching_option(flag) - used_options << option - - option.ensure_call(arg) + if flag.include?("=") + flag, arg = flag.split("=") end + + try_process(flag, arg) end Result.new(self).tap do |result| @@ -41,6 +41,17 @@ module Slop private + 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 + end + end + def matching_option(flag) options.find { |o| o.flags.include?(flag) } end |