* lib/optparse.rb (OptionParser#make_switch): pass arguments directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4d24c82ccf
commit
eba3d4587f
@ -1,3 +1,7 @@
|
|||||||
|
Sun Oct 1 23:12:19 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/optparse.rb (OptionParser#make_switch): pass arguments directly.
|
||||||
|
|
||||||
Sat Sep 30 15:11:26 2006 Tadayoshi Funaba <tadf@dotrb.org>
|
Sat Sep 30 15:11:26 2006 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
* lib/date.rb, lib/date/format.rb: updated based on date2 3.9.4.
|
* lib/date.rb, lib/date/format.rb: updated based on date2 3.9.4.
|
||||||
|
@ -398,6 +398,7 @@ class OptionParser
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :nodoc:
|
||||||
def add_banner(to)
|
def add_banner(to)
|
||||||
unless @short or @long
|
unless @short or @long
|
||||||
s = desc.join
|
s = desc.join
|
||||||
@ -406,6 +407,7 @@ class OptionParser
|
|||||||
to
|
to
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :nodoc:
|
||||||
def match_nonswitch?(str)
|
def match_nonswitch?(str)
|
||||||
@pattern =~ str unless @short or @long
|
@pattern =~ str unless @short or @long
|
||||||
end
|
end
|
||||||
@ -425,7 +427,7 @@ class OptionParser
|
|||||||
#
|
#
|
||||||
# Raises an exception if any arguments given.
|
# Raises an exception if any arguments given.
|
||||||
#
|
#
|
||||||
def parse(arg, argv, &error)
|
def parse(arg, argv)
|
||||||
yield(NeedlessArgument, arg) if arg
|
yield(NeedlessArgument, arg) if arg
|
||||||
conv_arg(arg)
|
conv_arg(arg)
|
||||||
end
|
end
|
||||||
@ -603,8 +605,7 @@ class OptionParser
|
|||||||
def search(id, key)
|
def search(id, key)
|
||||||
if list = __send__(id)
|
if list = __send__(id)
|
||||||
val = list.fetch(key) {return nil}
|
val = list.fetch(key) {return nil}
|
||||||
return val unless block_given?
|
block_given? ? yield(val) : val
|
||||||
yield(val)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -642,6 +643,7 @@ class OptionParser
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :nodoc:
|
||||||
def add_banner(to)
|
def add_banner(to)
|
||||||
list.each do |opt|
|
list.each do |opt|
|
||||||
if opt.respond_to?(:add_banner)
|
if opt.respond_to?(:add_banner)
|
||||||
@ -1055,7 +1057,7 @@ class OptionParser
|
|||||||
# Handler for the parsed argument value. Either give a block or pass a
|
# Handler for the parsed argument value. Either give a block or pass a
|
||||||
# Proc or Method as an argument.
|
# Proc or Method as an argument.
|
||||||
#
|
#
|
||||||
def make_switch(*opts, &block)
|
def make_switch(opts, block = nil)
|
||||||
short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
|
short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
|
||||||
ldesc, sdesc, desc, arg = [], [], []
|
ldesc, sdesc, desc, arg = [], [], []
|
||||||
default_style = Switch::NoArgument
|
default_style = Switch::NoArgument
|
||||||
@ -1175,7 +1177,7 @@ class OptionParser
|
|||||||
end
|
end
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -1190,7 +1192,7 @@ class OptionParser
|
|||||||
alias def_option define
|
alias def_option define
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -1204,7 +1206,7 @@ class OptionParser
|
|||||||
alias def_head_option define_head
|
alias def_head_option define_head
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -1786,5 +1788,5 @@ if $0 == __FILE__
|
|||||||
Version = OptionParser::Version
|
Version = OptionParser::Version
|
||||||
ARGV.options {|q|
|
ARGV.options {|q|
|
||||||
q.parse!.empty? or puts "what's #{ARGV.join(' ')}?"
|
q.parse!.empty? or puts "what's #{ARGV.join(' ')}?"
|
||||||
} or exit 1
|
} or abort(ARGV.options.to_s)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user