un.rb: help order
* lib/un.rb (UN#help): show help messages in the given order. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0fc3541664
commit
eb06e8d3ad
16
lib/un.rb
16
lib/un.rb
@ -351,15 +351,25 @@ module UN # :nodoc:
|
|||||||
module_function
|
module_function
|
||||||
def help(argv, output: $stdout)
|
def help(argv, output: $stdout)
|
||||||
all = argv.empty?
|
all = argv.empty?
|
||||||
|
cmd = nil
|
||||||
|
if all
|
||||||
|
store = proc {|msg| output << msg}
|
||||||
|
else
|
||||||
|
messages = {}
|
||||||
|
store = proc {|msg| messages[cmd] = msg}
|
||||||
|
end
|
||||||
open(__FILE__) do |me|
|
open(__FILE__) do |me|
|
||||||
while me.gets("##\n")
|
while me.gets("##\n")
|
||||||
if help = me.gets("\n\n")
|
if help = me.gets("\n\n")
|
||||||
if all or argv.delete help[/^#\s*ruby\s.*-e\s+(\w+)/, 1]
|
if all or argv.include?(cmd = help[/^#\s*ruby\s.*-e\s+(\w+)/, 1])
|
||||||
output << help.gsub(/^# ?/, "")
|
store[help.gsub(/^# ?/, "")]
|
||||||
break if !all and argv.empty?
|
break unless all or argv.size > messages.size
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if messages
|
||||||
|
argv.each {|cmd| output << messages[cmd]}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user