1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/optparse.rb (OptionParser#make_switch, OptionParser#order!):

added non-option and end-of-args handler.  [ruby-talk:136878]
  (EXPERIMENTAL


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2005-04-12 10:30:45 +00:00
parent c594a95a57
commit bea190a1fc
2 changed files with 59 additions and 12 deletions

View file

@ -1,3 +1,9 @@
Tue Apr 12 19:30:36 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser#make_switch, OptionParser#order!):
added non-option and end-of-args handler. [ruby-talk:136878]
(EXPERIMENTAL
Tue Apr 12 15:33:09 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tcltklib.c (ip_finalize): better modification than the

View file

@ -416,6 +416,14 @@ class OptionParser
self
end
def add_banner(to)
if @short and @short.empty? and @long and @long.empty?
s = desc.join
to << " [" + s + "]..." unless s.empty?
end
to
end
#
# Switch that takes no arguments.
#
@ -634,6 +642,15 @@ class OptionParser
__send__(id).complete(opt, icase, *pat, &block)
end
#
# OptionParser::List#each_option
#
# Iterates for each options.
#
def each_option(&block)
list.each(&block)
end
#
# OptionParser::List#summarize(*args) {...}
#
@ -656,6 +673,15 @@ class OptionParser
end
end
end
def add_banner(to)
list.each do |opt|
if opt.respond_to?(:add_banner)
opt.add_banner(to)
end
end
to
end
end
#
@ -890,7 +916,11 @@ class OptionParser
attr_accessor :summary_width, :summary_indent
def banner
@banner ||= "Usage: #{program_name} [options]"
unless @banner
@banner = "Usage: #{program_name} [options]"
@stack.reverse_each {|el|el.add_banner(@banner)}
end
@banner
end
def program_name
@ -1178,11 +1208,15 @@ class OptionParser
end
default_pattern, conv = search(:atype, default_style.pattern) unless default_pattern
s = if short.empty? and long.empty?
raise ArgumentError, "no switch given" if style or pattern or block
desc
if !(short.empty? and long.empty?)
s = (style || default_style).new(pattern || default_pattern,
conv, sdesc, ldesc, arg, desc, block)
elsif !block
raise ArgumentError, "no switch given" if style or pattern
s = desc
else
(style || default_style).new(pattern || default_pattern,
short << pattern
s = (style || default_style).new(pattern,
conv, sdesc, ldesc, arg, desc, block)
end
return s, short, long,
@ -1312,13 +1346,20 @@ class OptionParser
# non-option argument
else
catch(:prune) do
visit(:each_option) do |sw|
sw.block.call(arg) if sw.pattern and sw.pattern =~ arg
end
nonopt.call(arg)
end
end
end
nil
}
visit(:search, :short, nil) {|sw| sw.block.call(argv) if !sw.pattern}
argv
end