summaryrefslogtreecommitdiff
path: root/lib/optparse/ac.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/optparse/ac.rb')
-rw-r--r--lib/optparse/ac.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/optparse/ac.rb b/lib/optparse/ac.rb
index fb0883f97a..23fc740d10 100644
--- a/lib/optparse/ac.rb
+++ b/lib/optparse/ac.rb
@@ -1,7 +1,11 @@
# frozen_string_literal: false
-require 'optparse'
+require_relative '../optparse'
+#
+# autoconf-like options.
+#
class OptionParser::AC < OptionParser
+ # :stopdoc:
private
def _check_ac_args(name, block)
@@ -13,6 +17,9 @@ class OptionParser::AC < OptionParser
end
end
+ ARG_CONV = proc {|val| val.nil? ? true : val}
+ private_constant :ARG_CONV
+
def _ac_arg_enable(prefix, name, help_string, block)
_check_ac_args(name, block)
@@ -20,22 +27,34 @@ class OptionParser::AC < OptionParser
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
+ # :startdoc:
+
public
+ # Define <tt>--enable</tt> / <tt>--disable</tt> style option
+ #
+ # Appears as <tt>--enable-<i>name</i></tt> in help message.
def ac_arg_enable(name, help_string, &block)
_ac_arg_enable("enable", name, help_string, block)
end
+ # Define <tt>--enable</tt> / <tt>--disable</tt> style option
+ #
+ # Appears as <tt>--disable-<i>name</i></tt> in help message.
def ac_arg_disable(name, help_string, &block)
_ac_arg_enable("disable", name, help_string, block)
end
+ # Define <tt>--with</tt> / <tt>--without</tt> style option
+ #
+ # Appears as <tt>--with-<i>name</i></tt> in help message.
def ac_arg_with(name, help_string, &block)
_check_ac_args(name, block)