Skip to content

Commit

Permalink
Stop multiple switches from trashing arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradIrwin committed May 31, 2012
1 parent d50a2d8 commit 76d09b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/slop.rb
Expand Up @@ -466,8 +466,12 @@ def execute_option(option, argument, index, item = nil)
return
end

@trash << index + 1 unless item && item.end_with?("=#{argument}")
option.value = argument
if argument
@trash << index + 1 unless item && item.end_with?("=#{argument}")
option.value = argument
else
option.value = option.count > 0
end

if option.match? && !argument.match(option.config[:match])
raise InvalidArgumentError, "#{argument} is an invalid argument"
Expand All @@ -485,11 +489,11 @@ def execute_option(option, argument, index, item = nil)
#
# Returns nothing.
def execute_multiple_switches(option, argument, index)
execute_option(option, argument, index)
execute_option(option, nil, index)
argument.split('').each do |key|
opt = fetch_option(key)
opt.count += 1
execute_option(opt, argument, index, key)
execute_option(opt, nil, index, key)
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/slop_test.rb
Expand Up @@ -218,6 +218,12 @@ def temp_stderr
assert_equal 'abc123', opts[:f]
end

test "muiltiple_switches should not trash arguments" do
opts = Slop.new{ on :f; on :b }
args = opts.parse!(%w'-fb foo')
assert_equal %w'foo', args
end

test "setting/getting the banner" do
opts = Slop.new :banner => 'foo'
assert_equal 'foo', opts.banner
Expand Down

0 comments on commit 76d09b2

Please sign in to comment.