Skip to content

Commit

Permalink
Allow --enable/--disable options to take an argument
Browse files Browse the repository at this point in the history
[Bug #15850]
  • Loading branch information
nobu committed May 15, 2019
1 parent f54aa6c commit c9b28fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/optparse/ac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ def _check_ac_args(name, block)
end
end

ARG_CONV = proc {|val| val.nil? ? true : val}

def _ac_arg_enable(prefix, name, help_string, block)
_check_ac_args(name, block)

sdesc = []
ldesc = ["--#{prefix}-#{name}"]
desc = [help_string]
q = name.downcase
enable = Switch::NoArgument.new(nil, proc {true}, sdesc, ldesc, nil, desc, block)
disable = Switch::NoArgument.new(nil, proc {false}, sdesc, ldesc, nil, desc, block)
ac_block = proc {|val| block.call(ARG_CONV.call(val))}
enable = Switch::PlacedArgument.new(nil, ARG_CONV, sdesc, ldesc, nil, desc, ac_block)
disable = Switch::NoArgument.new(nil, proc {false}, sdesc, ldesc, nil, desc, ac_block)
top.append(enable, [], ["enable-" + q], disable, ['disable-' + q])
enable
end
Expand Down
7 changes: 7 additions & 0 deletions test/optparse/test_autoconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def test_enable
assert_equal(true, @bar)
end

def test_enable_value
@opt.parse!(%w"--enable-foo=A")
assert_equal("A", @foo)
@opt.parse!(%w"--enable-bar=B")
assert_equal("B", @bar)
end

def test_disable
@opt.parse!(%w"--disable-foo")
assert_equal(false, @foo)
Expand Down

0 comments on commit c9b28fd

Please sign in to comment.