[ruby/optparse] Change *opts to *params, to avoid confusion
https://github.com/ruby/optparse/commit/f5f5e202dd
This commit is contained in:
parent
eca8ffaa0b
commit
7846f3201a
@ -72,10 +72,10 @@
|
|||||||
# require 'optparse'
|
# require 'optparse'
|
||||||
#
|
#
|
||||||
# options = {}
|
# options = {}
|
||||||
# OptionParser.new do |opts|
|
# OptionParser.new do |parser|
|
||||||
# opts.banner = "Usage: example.rb [options]"
|
# parser.banner = "Usage: example.rb [options]"
|
||||||
#
|
#
|
||||||
# opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
# parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
||||||
# options[:verbose] = v
|
# options[:verbose] = v
|
||||||
# end
|
# end
|
||||||
# end.parse!
|
# end.parse!
|
||||||
@ -96,15 +96,15 @@
|
|||||||
# def self.parse(options)
|
# def self.parse(options)
|
||||||
# args = Options.new("world")
|
# args = Options.new("world")
|
||||||
#
|
#
|
||||||
# opt_parser = OptionParser.new do |opts|
|
# opt_parser = OptionParser.new do |parser|
|
||||||
# opts.banner = "Usage: example.rb [options]"
|
# parser.banner = "Usage: example.rb [options]"
|
||||||
#
|
#
|
||||||
# opts.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
|
# parser.on("-nNAME", "--name=NAME", "Name to say hello to") do |n|
|
||||||
# args.name = n
|
# args.name = n
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# opts.on("-h", "--help", "Prints this help") do
|
# parser.on("-h", "--help", "Prints this help") do
|
||||||
# puts opts
|
# puts parser
|
||||||
# exit
|
# exit
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
@ -241,10 +241,10 @@
|
|||||||
# require 'optparse'
|
# require 'optparse'
|
||||||
#
|
#
|
||||||
# params = {}
|
# params = {}
|
||||||
# OptionParser.new do |opts|
|
# OptionParser.new do |parser|
|
||||||
# opts.on('-a')
|
# parser.on('-a')
|
||||||
# opts.on('-b NUM', Integer)
|
# parser.on('-b NUM', Integer)
|
||||||
# opts.on('-v', '--verbose')
|
# parser.on('-v', '--verbose')
|
||||||
# end.parse!(into: params)
|
# end.parse!(into: params)
|
||||||
#
|
#
|
||||||
# p params
|
# p params
|
||||||
@ -1310,13 +1310,16 @@ XXX
|
|||||||
private :notwice
|
private :notwice
|
||||||
|
|
||||||
SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # :nodoc:
|
SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # :nodoc:
|
||||||
|
|
||||||
|
# :call-seq:
|
||||||
|
# make_switch(params, block = nil)
|
||||||
#
|
#
|
||||||
# Creates an OptionParser::Switch from the parameters. The parsed argument
|
# Creates an OptionParser::Switch from the parameters. The parsed argument
|
||||||
# value is passed to the given block, where it can be processed.
|
# value is passed to the given block, where it can be processed.
|
||||||
#
|
#
|
||||||
# See at the beginning of OptionParser for some full examples.
|
# See at the beginning of OptionParser for some full examples.
|
||||||
#
|
#
|
||||||
# +opts+ can include the following elements:
|
# +params+ can include the following elements:
|
||||||
#
|
#
|
||||||
# [Argument style:]
|
# [Argument style:]
|
||||||
# One of the following:
|
# One of the following:
|
||||||
@ -1503,11 +1506,16 @@ XXX
|
|||||||
nolong
|
nolong
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :call-seq:
|
||||||
|
# define(*params, &block)
|
||||||
|
#
|
||||||
def define(*opts, &block)
|
def define(*opts, &block)
|
||||||
top.append(*(sw = make_switch(opts, block)))
|
top.append(*(sw = make_switch(opts, block)))
|
||||||
sw[0]
|
sw[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :call-seq:
|
||||||
|
# on(*params, &block)
|
||||||
#
|
#
|
||||||
# Add option switch and handler. See #make_switch for an explanation of
|
# Add option switch and handler. See #make_switch for an explanation of
|
||||||
# parameters.
|
# parameters.
|
||||||
@ -1518,11 +1526,16 @@ XXX
|
|||||||
end
|
end
|
||||||
alias def_option define
|
alias def_option define
|
||||||
|
|
||||||
|
# :call-seq:
|
||||||
|
# define_head(*params, &block)
|
||||||
|
#
|
||||||
def define_head(*opts, &block)
|
def define_head(*opts, &block)
|
||||||
top.prepend(*(sw = make_switch(opts, block)))
|
top.prepend(*(sw = make_switch(opts, block)))
|
||||||
sw[0]
|
sw[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :call-seq:
|
||||||
|
# on_head(*params, &block)
|
||||||
#
|
#
|
||||||
# Add option switch like with #on, but at head of summary.
|
# Add option switch like with #on, but at head of summary.
|
||||||
#
|
#
|
||||||
@ -1532,11 +1545,17 @@ XXX
|
|||||||
end
|
end
|
||||||
alias def_head_option define_head
|
alias def_head_option define_head
|
||||||
|
|
||||||
|
# :call-seq:
|
||||||
|
# define_tail(*params, &block)
|
||||||
|
#
|
||||||
def define_tail(*opts, &block)
|
def define_tail(*opts, &block)
|
||||||
base.append(*(sw = make_switch(opts, block)))
|
base.append(*(sw = make_switch(opts, block)))
|
||||||
sw[0]
|
sw[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# :call-seq:
|
||||||
|
# on_tail(*params, &block)
|
||||||
#
|
#
|
||||||
# Add option switch like with #on, but at tail of summary.
|
# Add option switch like with #on, but at tail of summary.
|
||||||
#
|
#
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
class OptionParser
|
class OptionParser
|
||||||
|
# :call-seq:
|
||||||
|
# define_by_keywords(options, method, **params)
|
||||||
|
#
|
||||||
def define_by_keywords(options, meth, **opts)
|
def define_by_keywords(options, meth, **opts)
|
||||||
meth.parameters.each do |type, name|
|
meth.parameters.each do |type, name|
|
||||||
case type
|
case type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user