[ruby/optparse] [DOC] Add missing documents

https://github.com/ruby/optparse/commit/33956ce93f
This commit is contained in:
Nobuyoshi Nakada 2024-02-12 01:07:05 +09:00 committed by git
parent a3ceb69168
commit bbccabe6d6
3 changed files with 55 additions and 4 deletions

View File

@ -8,7 +8,6 @@
# See OptionParser for documentation. # See OptionParser for documentation.
# #
#-- #--
# == Developer Documentation (not for RDoc output) # == Developer Documentation (not for RDoc output)
# #
@ -425,6 +424,7 @@
# If you have any questions, file a ticket at http://bugs.ruby-lang.org. # If you have any questions, file a ticket at http://bugs.ruby-lang.org.
# #
class OptionParser class OptionParser
# The version string
OptionParser::Version = "0.4.0" OptionParser::Version = "0.4.0"
# :stopdoc: # :stopdoc:
@ -438,6 +438,8 @@ class OptionParser
# and resolved against a list of acceptable values. # and resolved against a list of acceptable values.
# #
module Completion module Completion
# :nodoc:
def self.regexp(key, icase) def self.regexp(key, icase)
Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'), icase) Regexp.new('\A' + Regexp.quote(key).gsub(/\w+\b/, '\&\w*'), icase)
end end
@ -510,6 +512,8 @@ class OptionParser
# RequiredArgument, etc. # RequiredArgument, etc.
# #
class Switch class Switch
# :nodoc:
attr_reader :pattern, :conv, :short, :long, :arg, :desc, :block attr_reader :pattern, :conv, :short, :long, :arg, :desc, :block
# #
@ -715,10 +719,10 @@ class OptionParser
conv_arg(arg) conv_arg(arg)
end end
def self.incompatible_argument_styles(*) def self.incompatible_argument_styles(*) # :nodoc:
end end
def self.pattern def self.pattern # :nodoc:
Object Object
end end
@ -804,6 +808,8 @@ class OptionParser
# matching pattern and converter pair. Also provides summary feature. # matching pattern and converter pair. Also provides summary feature.
# #
class List class List
# :nodoc:
# Map from acceptable argument types to pattern and converter pairs. # Map from acceptable argument types to pattern and converter pairs.
attr_reader :atype attr_reader :atype
@ -1185,6 +1191,11 @@ XXX
end end
@stack = [DefaultList] @stack = [DefaultList]
#
# Returns the global top option list.
#
# Do not use directly.
#
def self.top() DefaultList end def self.top() DefaultList end
# #
@ -1297,10 +1308,24 @@ XXX
end end
end end
#
# Shows warning message with the program name
#
# +mesg+:: Message, defaulted to +$!+.
#
# See Kernel#warn.
#
def warn(mesg = $!) def warn(mesg = $!)
super("#{program_name}: #{mesg}") super("#{program_name}: #{mesg}")
end end
#
# Shows message with the program name then aborts.
#
# +mesg+:: Message, defaulted to +$!+.
#
# See Kernel#abort.
#
def abort(mesg = $!) def abort(mesg = $!)
super("#{program_name}: #{mesg}") super("#{program_name}: #{mesg}")
end end
@ -2342,7 +2367,8 @@ XXX
super super
obj.instance_eval {@optparse = nil} obj.instance_eval {@optparse = nil}
end end
def initialize(*args)
def initialize(*args) # :nodoc:
super super
@optparse = nil @optparse = nil
end end

View File

@ -1,7 +1,11 @@
# frozen_string_literal: false # frozen_string_literal: false
require_relative '../optparse' require_relative '../optparse'
#
# autoconf-like options.
#
class OptionParser::AC < OptionParser class OptionParser::AC < OptionParser
# :stopdoc:
private private
def _check_ac_args(name, block) def _check_ac_args(name, block)
@ -14,6 +18,7 @@ class OptionParser::AC < OptionParser
end end
ARG_CONV = proc {|val| val.nil? ? true : val} ARG_CONV = proc {|val| val.nil? ? true : val}
private_constant :ARG_CONV
def _ac_arg_enable(prefix, name, help_string, block) def _ac_arg_enable(prefix, name, help_string, block)
_check_ac_args(name, block) _check_ac_args(name, block)
@ -29,16 +34,27 @@ class OptionParser::AC < OptionParser
enable enable
end end
# :startdoc:
public 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) def ac_arg_enable(name, help_string, &block)
_ac_arg_enable("enable", name, help_string, block) _ac_arg_enable("enable", name, help_string, block)
end 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) def ac_arg_disable(name, help_string, &block)
_ac_arg_enable("disable", name, help_string, block) _ac_arg_enable("disable", name, help_string, block)
end 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) def ac_arg_with(name, help_string, &block)
_check_ac_args(name, block) _check_ac_args(name, block)

View File

@ -2,6 +2,11 @@
# OptionParser internal utility # OptionParser internal utility
class << OptionParser class << OptionParser
#
# Shows version string in packages if Version is defined.
#
# +pkgs+:: package list
#
def show_version(*pkgs) def show_version(*pkgs)
progname = ARGV.options.program_name progname = ARGV.options.program_name
result = false result = false
@ -47,6 +52,8 @@ class << OptionParser
result result
end end
# :stopdoc:
def each_const(path, base = ::Object) def each_const(path, base = ::Object)
path.split(/::|\//).inject(base) do |klass, name| path.split(/::|\//).inject(base) do |klass, name|
raise NameError, path unless Module === klass raise NameError, path unless Module === klass
@ -68,4 +75,6 @@ class << OptionParser
end end
end end
end end
# :startdoc:
end end