lib/subcommand.rb
##
# specify a single command and all its options
# If multiple names are given, they are treated as aliases.
# Do repeatedly for each command
# Yields the optionparser
specify a single command and all its options
If multiple names are given, they are treated as aliases.
Do repeatedly for each command
Yields the optionparser
specify a single command and all its options If multiple names are given they are treated as aliases . Do repeatedly for each command Yields the optionparser
def command *names
    name = names.shift
    @commands ||= {}
    @aliases ||= {}
    if names.length > 0
      names.each do |n| 
        @aliases[n.to_s] = name.to_s
      end
    end
    opt = lambda { OptionParser.new do |opts|
      yield opts
      opts.banner << "\n#{opts.description}\n" if opts.description
    end }
    @commands[name.to_s] = opt
  end
def command * names name = names . shift @commands ||= { } @aliases ||= { } if names . length > 0 names . each do | n | @aliases [ n . to_s ] = name . to_s end end opt = lambda { OptionParser . new do | opts | yield opts opts . banner << "\n#{opts.description}\n" if opts . description end } @commands [ name . to_s ] = opt end
specify a single command and all its options
If multiple names are given, they are treated as aliases.
specify a single command and all its options If multiple names are given they are treated as aliases .
#puts "aliases #{n} => #{name} " # Thanks to Robert Klemme for the lazy loading idea. # append desc to banner in next line
names
<not_specific>