class Rootage::Help

Constants

FORMAT

Known format table.

Attributes

cmd[R]

Public Class Methods

find(format) click to toggle source

Find the named format.

@param format [Symbol]

format name

@return [Class]

help class
# File lib/rootage/help.rb, line 23
def self.find(format)
  Help::FORMAT[format]
end
new(cmd) click to toggle source

@param [Command]

command object that has this help
# File lib/rootage/help.rb, line 31
def initialize(cmd)
  @cmd = cmd
end
register(name, klass=self) click to toggle source

Register the help format. This is for subclasses.

@param name [Symbol]

format name

@param klass [Class]

help class

@return [void]

# File lib/rootage/help.rb, line 13
def self.register(name, klass=self)
  Help::FORMAT[name] = klass
end

Private Instance Methods

argument_heading(arg) click to toggle source

Return a heading of the argument item.

@param arg [Command::ArgumentItem]

an argument item

@return [String]

a heading
# File lib/rootage/help.rb, line 68
def argument_heading(arg)
  "<%s>" % (arg.heading || arg.name)
end
argument_heading_width() click to toggle source

Return max width size of argument headings.

@return [Integer]

max width
# File lib/rootage/help.rb, line 76
def argument_heading_width
  arguments.max_by{|item| item.name.size}.name.size + 2
end
argument_list() click to toggle source

Return a string of argument list.

@return [String]

argument list
# File lib/rootage/help.rb, line 84
def argument_list
  arguments.map{|arg| argument_heading(arg)}.join(" ")
end
arguments() click to toggle source

Return argument items for the command.

@return [Array<Argument>]

arguments
# File lib/rootage/help.rb, line 41
def arguments
  @cmd.argument_definition.table.values
end
option_heading(item) click to toggle source

Return a heading string for options help.

@return [String]

option heading string
# File lib/rootage/help.rb, line 92
def option_heading(item)
  template = item.arg ? "%s #{item.arg}" : "%s"
  if item.short.nil?
    return template % item.long
  end
  if item.long.nil?
    return template % item.short
  end
  return template % "%s, %s" % [item.short, item.long]
end
option_heading_width() click to toggle source

Return max width of option headings.

@return [Integer]

max width
# File lib/rootage/help.rb, line 107
def option_heading_width
  option_heading(options.max_by{|item| option_heading(item).size}).size
end
options() click to toggle source

Return option items for the command. The result is sorted by long option names.

@return [Array<Option>]

options
# File lib/rootage/help.rb, line 50
def options
  @cmd.option_definition.table.values.sort{|a,b| a.long <=> b.long} + [HelpOption.help]
end
subcommand_heading_width() click to toggle source

Return the max width of subcommand headings.

@return [Integer]

max width of subcommand headings
# File lib/rootage/help.rb, line 58
def subcommand_heading_width
  @cmd.subcommand.keys.max_by{|key| key.size}.size
end