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

* lib/optparse.rb: --version takes an optional argument; "all" or a list of package names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-08-31 03:25:11 +00:00
parent 782b6ceac3
commit 89c73f237e
3 changed files with 59 additions and 4 deletions

View file

@ -1,3 +1,8 @@
Sun Aug 31 12:25:06 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* lib/optparse.rb: --version takes an optional argument; "all" or
a list of package names.
Sun Aug 31 10:17:02 2003 Tadayoshi Funaba <tadf@dotrb.org> Sun Aug 31 10:17:02 2003 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date/format.rb: yyyy/mm is not an acceptable format. * lib/date/format.rb: yyyy/mm is not an acceptable format.

View file

@ -609,12 +609,21 @@ Default options, which never appear in option summary.
puts ARGV.options puts ARGV.options
exit exit
end end
DefaultList.long['version'] = Switch::NoArgument.new do DefaultList.long['version'] = Switch::OptionalArgument.new do |pkg|
if v = ARGV.options.ver if pkg
puts v begin
exit require 'optparse/version'
rescue LoadError
pkg = nil
else
show_version(*pkg.split(/,/))
end end
end end
unless pkg
puts v if v = ARGV.options.ver
end
exit
end
=begin =begin
=== Class methods === Class methods

41
lib/optparse/version.rb Normal file
View file

@ -0,0 +1,41 @@
# OptionParser internal utility
class << OptionParser
def show_version(*pkg)
progname = ARGV.options.program_name
show = proc do |klass, version|
version = version.join(".") if Array === version
str = "#{progname}: #{klass} version #{version}"
if klass.const_defined?(:Release)
str << " (#{klass.const_get(:Release)})"
end
puts str
end
if pkg.size == 1 and pkg[0] == "all"
self.search_const(::Object, "Version", &show)
else
pkg.each do |pkg|
/\A[A-Z]\w*((::|\/)[A-Z]\w*)*\z/ni =~ pkg or next
begin
pkg = eval(pkg)
show.call(pkg, pkg.const_defined?(:Version) ? pkg.const_get(:Version) : "unknown")
rescue NameError
puts "#{progname}: #$!"
end
end
end
exit
end
def search_const(klass, name)
klasses = [klass]
while klass = klasses.shift
klass.constants.each do |cname|
klass.const_defined?(cname) or next
const = klass.const_get(cname)
yield klass, const if cname == name
klasses << const if Module === const and const != ::Object
end
end
end
end