Method: Clio::Usage::Command#parse

Defined in:
lib/clio/usage/command.rb

#parse(argv) ⇒ Object

# Usage text.

#
def to_s
  #s = [full_name]
  s = [name]

  case options.size
  when 0
  when 1, 2, 3
    s.concat(options.collect{ |o| "[#{o.to_s.strip}]" })
  else
    s << "[switches]"
  end

# switches? vs. options

  s << arguments.join(' ') unless arguments.empty?

  case commands.size
  when 0
  when 1
    s << commands.join('')
  when 2, 3
    s << '[' + commands.join(' | ') + ']'
  else
    s << 'command'
  end

  s.flatten.join(' ')
end

# Help text.
#
def to_s_help
  s = []
  unless help.empty?
    s << help
    s << ''
  end
  s << "Usage:"
  s << "  " + to_s
  unless commands.empty?
    s << ''
    s << 'Commands:'
    s.concat(commands.collect{ |x| "  %-20s %s" % [x.key, x.help] }.sort)
  end
  unless arguments.empty?
    s << ''
    s << "Arguments:"
    s.concat(arguments.collect{ |x| "  %-20s %s" % [x, x.help] })
  end
  unless options.empty?
    s << ''
    s << 'Switches:'
    s.concat(options.collect{ |x| "  %-20s %s" % [x, x.help] })
  end
  s.flatten.join("\n")
end


131
132
133
# File 'lib/clio/usage/command.rb', line 131

def parse(argv)
  Parser.new(self, argv).parse #(argv)
end