From 0fc35416644391b99759cceb7d992d802616b495 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 5 Jul 2013 13:43:22 +0000 Subject: un.rb: help message * lib/un.rb (setup): show help message by help method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41800 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/un.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/un.rb b/lib/un.rb index 78d6d6e91c..2abdc7608f 100644 --- a/lib/un.rb +++ b/lib/un.rb @@ -34,6 +34,7 @@ end # :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) 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 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 -- cgit v1.2.3