Module: UN

Defined in:
lib/un.rb

Overview

:nodoc:

Class Method Summary collapse

Class Method Details

.help(argv, output: $stdout) ⇒ Object



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/un.rb', line 352

def help(argv, output: $stdout)
  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|
    while me.gets("##\n")
      if help = me.gets("\n\n")
        if all or argv.include?(cmd = help[/^#\s*ruby\s.*-e\s+(\w+)/, 1])
          store[help.gsub(/^# ?/, "")]
          break unless all or argv.size > messages.size
        end
      end
    end
  end
  if messages
    argv.each {|cmd| output << messages[cmd]}
  end
end