[前][次][番号順一覧][スレッド一覧]

ruby-changes:29748

From: nobu <ko1@a...>
Date: Fri, 5 Jul 2013 22:43:39 +0900 (JST)
Subject: [ruby-changes:29748] nobu:r41800 (trunk): un.rb: help message

nobu	2013-07-05 22:43:22 +0900 (Fri, 05 Jul 2013)

  New Revision: 41800

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41800

  Log:
    un.rb: help message
    
    * lib/un.rb (setup): show help message by help method.

  Modified files:
    trunk/lib/un.rb

Index: lib/un.rb
===================================================================
--- lib/un.rb	(revision 41799)
+++ lib/un.rb	(revision 41800)
@@ -34,6 +34,7 @@ end https://github.com/ruby/ruby/blob/trunk/lib/un.rb#L34
 
 # :nodoc:
 def setup(options = "", *long_options)
+  caller = caller_locations(1, 1)[0].label
   opt_hash = {}
   argv = []
   OptionParser.new do |o|
@@ -54,6 +55,10 @@ def setup(options = "", *long_options) https://github.com/ruby/ruby/blob/trunk/lib/un.rb#L55
       end
     end
     o.on("-v") do opt_hash[:verbose] = true end
+    o.on("--help") do
+      UN.help([caller])
+      exit
+    end
     o.order!(ARGV) do |x|
       if /[*?\[{]/ =~ x
         argv.concat(Dir[x])
@@ -338,12 +343,20 @@ end https://github.com/ruby/ruby/blob/trunk/lib/un.rb#L343
 
 def help
   setup do |argv,|
+    UN.help(argv)
+  end
+end
+
+module UN # :nodoc:
+  module_function
+  def help(argv, output: $stdout)
     all = argv.empty?
     open(__FILE__) do |me|
       while me.gets("##\n")
         if help = me.gets("\n\n")
           if all or argv.delete help[/^#\s*ruby\s.*-e\s+(\w+)/, 1]
-            print help.gsub(/^# ?/, "")
+            output << help.gsub(/^# ?/, "")
+            break if !all and argv.empty?
           end
         end
       end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]