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::Officious): moved from DefaultList.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-11-09 05:27:58 +00:00
parent 7c5c394f09
commit 4c718c753e
3 changed files with 83 additions and 45 deletions

View file

@ -1,3 +1,7 @@
Tue Nov 9 14:27:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser::Officious): moved from DefaultList.
Tue Nov 9 00:50:06 2004 Dave Thomas <dave@pragprog.com> Tue Nov 9 00:50:06 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/rdoc.rb: Change version numbering of RDoc and ri * lib/rdoc/rdoc.rb: Change version numbering of RDoc and ri
@ -46,11 +50,11 @@ Sat Nov 6 11:18:59 2004 Tadayoshi Funaba <tadf@dotrb.org>
Fri Nov 5 19:07:16 2004 NARUSE, Yui <naruse@ruby-lang.org> Fri Nov 5 19:07:16 2004 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf: follow CVS Head of original nkf. * ext/nkf: follow CVS Head of original nkf.
Fri Nov 5 18:12:42 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Fri Nov 5 18:12:42 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/scrollable.rb: divide Scrollable module into * ext/tk/lib/tk/scrollable.rb: divide Scrollable module into
X_Scrollable and Y_Scrollable X_Scrollable and Y_Scrollable
* ext/tk/lib/tk/entry.rb: include X_Scrollable instead of Scrollable * ext/tk/lib/tk/entry.rb: include X_Scrollable instead of Scrollable
@ -100,8 +104,8 @@ Thu Nov 4 21:25:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Thu Nov 4 21:13:48 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp> Thu Nov 4 21:13:48 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c(typelib_file_from_typelib): search "win16" * ext/win32ole/win32ole.c(typelib_file_from_typelib): search "win16"
entry to get library path. entry to get library path.
* ext/win32ole/win32ole.c(oletypelib_path): ditto. * ext/win32ole/win32ole.c(oletypelib_path): ditto.
@ -140,12 +144,12 @@ Wed Nov 3 17:19:59 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
Wed Nov 3 17:02:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Wed Nov 3 17:02:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: support to use different Tcl commands between * ext/tk/lib/tk.rb: support to use different Tcl commands between
configure and configinfo configure and configinfo
* ext/tk/lib/font.rb: ditto. * ext/tk/lib/font.rb: ditto.
* ext/tk/lib/itemconfig.rb: support to use different Tcl commands * ext/tk/lib/itemconfig.rb: support to use different Tcl commands
between item_configure and item_configinfo between item_configure and item_configinfo
* ext/tk/lib/itemfont.rb: ditto. * ext/tk/lib/itemfont.rb: ditto.
@ -159,7 +163,7 @@ Wed Nov 3 15:38:28 2004 Kouhei Sutou <kou@cozmixng.org>
* test/rss/*.rb: removed tab width configuration headers. * test/rss/*.rb: removed tab width configuration headers.
* test/rss/test_maker_{0.9,1.0}.rb: sort -> do_sort. * test/rss/test_maker_{0.9,1.0}.rb: sort -> do_sort.
* lib/rss/maker/*.rb: changed API to RSS version independence. * lib/rss/maker/*.rb: changed API to RSS version independence.
* lib/rss/maker/base.rb * lib/rss/maker/base.rb
@ -276,7 +280,7 @@ Sun Oct 31 14:18:56 2004 Minero Aoki <aamine@loveruby.net>
Sat Oct 30 15:24:41 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp> Sat Oct 30 15:24:41 2004 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: add WIN32OLE_TYPELIB class. add * ext/win32ole/win32ole.c: add WIN32OLE_TYPELIB class. add
WIN32OLE#ole_typelib method. WIN32OLE#ole_typelib method.
* ext/win32ole/tests/testOLETYPELIB.rb: add WIN32OLE_TYPELIB class. * ext/win32ole/tests/testOLETYPELIB.rb: add WIN32OLE_TYPELIB class.

View file

@ -718,30 +718,38 @@ class OptionParser
DefaultList.long[''] = Switch::NoArgument.new {throw :terminate} DefaultList.long[''] = Switch::NoArgument.new {throw :terminate}
# #
# Default options, which never appear in option summary. # OptionParser::Officious
# Default options for ARGV, which never appear in option summary.
#
Officious = {}
# --help # --help
# Shows option summary. # Shows option summary.
Officious['help'] = proc do |parser|
Switch::NoArgument.new do
puts parser.help
exit
end
end
# --version # --version
# Shows version string if (({::Version})) is defined. # Shows version string if (({::Version})) is defined.
# Officious['version'] = proc do |parser|
DefaultList.long['help'] = Switch::NoArgument.new do Switch::OptionalArgument.new do |pkg|
puts ARGV.options if pkg
exit begin
end require 'optparse/version'
DefaultList.long['version'] = Switch::OptionalArgument.new do |pkg| rescue LoadError
if pkg else
begin show_version(*pkg.split(/,/)) or
require 'optparse/version' abort("#{parser.program_name}: no version found in package #{pkg}")
rescue LoadError exit
pkg = nil end
else
show_version(*pkg.split(/,/))
end end
v = parser.ver or abort("#{parser.program_name}: version unknown")
puts v
exit
end end
unless pkg
v = ARGV.options.ver and puts v
end
exit
end end
# :startdoc: # :startdoc:
@ -809,9 +817,18 @@ class OptionParser
@banner = banner @banner = banner
@summary_width = width @summary_width = width
@summary_indent = indent @summary_indent = indent
add_officious
yield self if block_given? yield self if block_given?
end end
# :nodoc:
def add_officious
list = base()
Officious.each_pair do |opt, block|
list.long[opt] ||= block.call(self)
end
end
=begin =begin
--- OptionParser.terminate([arg]) --- OptionParser.terminate([arg])
Terminates option parsing. Optional parameter ((|arg|)) would be Terminates option parsing. Optional parameter ((|arg|)) would be
@ -907,7 +924,7 @@ class OptionParser
attr_writer :version, :release attr_writer :version, :release
def version def version
@version || (defined?(::Version) && ::Version) || (defined?(::VERSION) && ::VERSION) @version || (defined?(::Version) && ::Version)
end end
def release def release
@ -1562,6 +1579,21 @@ class OptionParser
s s
end end
=begin
: Regexp
Regular expression with option.
=end
accept(Regexp, %r"\A/((?:\\.|[^\\])*)/([[:alpha:]]+)?\z|.*") do |all, s, o|
f = 0
if o
f |= Regexp::IGNORECASE if /i/ =~ o
f |= Regexp::MULTILINE if /m/ =~ o
f |= Regexp::EXTENDED if /x/ =~ o
k = o.delete("^imx")
end
Regexp.new(s || all, f, k)
end
=begin =begin
= Exceptions = Exceptions
@ -1644,7 +1676,7 @@ argument.
((<OptionParser::ParseError>)) ((<OptionParser::ParseError>))
=end #'#"#`# =end #'#"#`#
class NeedlessArgument < ParseError class NeedlessArgument < ParseError
const_set(:Reason, 'needles argument'.freeze) const_set(:Reason, 'needless argument'.freeze)
end end
=begin =begin

View file

@ -3,45 +3,47 @@
class << OptionParser class << OptionParser
def show_version(*pkg) def show_version(*pkg)
progname = ARGV.options.program_name progname = ARGV.options.program_name
show = proc do |klass, version| result = false
version = version.join(".") if Array === version show = proc do |klass, cname, version|
str = "#{progname}" str = "#{progname}"
str << ": #{klass}" unless klass == Object unless klass == ::Object and cname == :VERSION
str << " version #{version}" version = version.join(".") if Array === version
case str << ": #{klass}" unless klass == Object
when klass.const_defined?(:Release) str << " version #{version}"
str << " (#{klass.const_get(:Release)})" end
when klass.const_defined?(:RELEASE) [:Release, :RELEASE].find do |rel|
str << " (#{klass.const_get(:Release)})" if klass.const_defined?(rel)
str << " (#{klass.const_get(rel)})"
end
end end
puts str puts str
result = true
end end
if pkg.size == 1 and pkg[0] == "all" if pkg.size == 1 and pkg[0] == "all"
self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version| self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version|
unless cname[1] == ?e and klass.const_defined?(:Version) unless cname[1] == ?e and klass.const_defined?(:Version)
show.call(klass, version) show.call(klass, cname.intern, version)
end end
end end
else else
pkg.each do |pkg| pkg.each do |pkg|
/\A[A-Z]\w*((::|\/)[A-Z]\w*)*\z/ni =~ pkg or next
begin begin
pkg = eval(pkg) pkg = pkg.split(/::|\//).inject(::Object) {|m, c| m.const_get(c)}
v = case v = case
when pkg.const_defined?(:Version) when pkg.const_defined?(:Version)
pkg.const_get(:Version) pkg.const_get(n = :Version)
when pkg.const_defined?(:VERSION) when pkg.const_defined?(:VERSION)
pkg.const_get(:VERSION) pkg.const_get(n = :VERSION)
else else
n = nil
"unknown" "unknown"
end end
show.call(pkg, v) show.call(pkg, n, v)
rescue NameError rescue NameError
puts "#{progname}: #$!"
end end
end end
end end
exit result
end end
def each_const(path, klass = ::Object) def each_const(path, klass = ::Object)