diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-09 05:27:58 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-09 05:27:58 +0000 |
| commit | a8e78c7a0e062755ce0e25cab270891badfa9ef3 (patch) | |
| tree | cb7196ae7bbd3d10aee786c18469d17706b1f3fa /lib/optparse | |
| parent | 77a3612d0acf401713a5b76ee5a530c7771c579f (diff) | |
| download | ruby-a8e78c7a0e062755ce0e25cab270891badfa9ef3.tar.gz ruby-a8e78c7a0e062755ce0e25cab270891badfa9ef3.tar.xz ruby-a8e78c7a0e062755ce0e25cab270891badfa9ef3.zip | |
* lib/optparse.rb (OptionParser::Officious): moved from DefaultList.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/optparse')
| -rw-r--r-- | lib/optparse/version.rb | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/optparse/version.rb b/lib/optparse/version.rb index 8e9983687..558d9d710 100644 --- a/lib/optparse/version.rb +++ b/lib/optparse/version.rb @@ -3,45 +3,47 @@ class << OptionParser def show_version(*pkg) progname = ARGV.options.program_name - show = proc do |klass, version| - version = version.join(".") if Array === version + result = false + show = proc do |klass, cname, version| str = "#{progname}" - str << ": #{klass}" unless klass == Object - str << " version #{version}" - case - when klass.const_defined?(:Release) - str << " (#{klass.const_get(:Release)})" - when klass.const_defined?(:RELEASE) - str << " (#{klass.const_get(:Release)})" + unless klass == ::Object and cname == :VERSION + version = version.join(".") if Array === version + str << ": #{klass}" unless klass == Object + str << " version #{version}" + end + [:Release, :RELEASE].find do |rel| + if klass.const_defined?(rel) + str << " (#{klass.const_get(rel)})" + end end puts str + result = true end if pkg.size == 1 and pkg[0] == "all" self.search_const(::Object, /\AV(?:ERSION|ersion)\z/) do |klass, cname, version| unless cname[1] == ?e and klass.const_defined?(:Version) - show.call(klass, version) + show.call(klass, cname.intern, version) end end else pkg.each do |pkg| - /\A[A-Z]\w*((::|\/)[A-Z]\w*)*\z/ni =~ pkg or next begin - pkg = eval(pkg) + pkg = pkg.split(/::|\//).inject(::Object) {|m, c| m.const_get(c)} v = case when pkg.const_defined?(:Version) - pkg.const_get(:Version) + pkg.const_get(n = :Version) when pkg.const_defined?(:VERSION) - pkg.const_get(:VERSION) + pkg.const_get(n = :VERSION) else + n = nil "unknown" end - show.call(pkg, v) + show.call(pkg, n, v) rescue NameError - puts "#{progname}: #$!" end end end - exit + result end def each_const(path, klass = ::Object) |
