ruby-changes:55729
From: Nobuyoshi <ko1@a...>
Date: Wed, 15 May 2019 17:35:20 +0900 (JST)
Subject: [ruby-changes:55729] Nobuyoshi Nakada: c9b28fd7ae (trunk): Allow --enable/--disable options to take an argument
https://git.ruby-lang.org/ruby.git/commit/?id=c9b28fd7ae From c9b28fd7ae5c5a79a74afebd5b191cfd2f31a65f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 15 May 2019 17:22:25 +0900 Subject: Allow --enable/--disable options to take an argument [Bug #15850] diff --git a/lib/optparse/ac.rb b/lib/optparse/ac.rb index fb0883f..9d52010 100644 --- a/lib/optparse/ac.rb +++ b/lib/optparse/ac.rb @@ -13,6 +13,8 @@ class OptionParser::AC < OptionParser https://github.com/ruby/ruby/blob/trunk/lib/optparse/ac.rb#L13 end end + ARG_CONV = proc {|val| val.nil? ? true : val} + def _ac_arg_enable(prefix, name, help_string, block) _check_ac_args(name, block) @@ -20,8 +22,9 @@ class OptionParser::AC < OptionParser https://github.com/ruby/ruby/blob/trunk/lib/optparse/ac.rb#L22 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 diff --git a/test/optparse/test_autoconf.rb b/test/optparse/test_autoconf.rb index 3be4a4c..45f2ba0 100644 --- a/test/optparse/test_autoconf.rb +++ b/test/optparse/test_autoconf.rb @@ -32,6 +32,13 @@ class TestOptionParser::AutoConf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/optparse/test_autoconf.rb#L32 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) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/