class HammerCLI::Help::Builder

Constants

DEFAULT_LABEL_INDENT

Attributes

richtext[R]

Public Class Methods

new(richtext = false) click to toggle source
Calls superclass method
# File lib/hammer_cli/help/builder.rb, line 8
def initialize(richtext = false)
  super()
  @richtext = richtext
end

Public Instance Methods

add_list(heading, items) click to toggle source
# File lib/hammer_cli/help/builder.rb, line 20
def add_list(heading, items)
  items.sort! do |a, b|
    a.help[0] <=> b.help[0]
  end
  items.reject! {|item| item.respond_to?(:hidden?) && item.hidden?}

  line
  heading(heading)

  label_width = DEFAULT_LABEL_INDENT
  items.each do |item|
    label = if !HammerCLI.context[:full_help] && item.respond_to?(:family) && item.family && !item.child?
              item.family.help.first
            else
              item.help.first
            end
    label_width = label.size if label.size > label_width
  end

  items.each do |item|
    if item.respond_to?(:child?) && item.child?
      next unless HammerCLI.context[:full_help]
    end
    label, description = if !HammerCLI.context[:full_help] && item.respond_to?(:family) && item.family
                           item.family.help
                         else
                           item.help
                         end
    description.gsub(/^(.)/) { Regexp.last_match(1).capitalize }.wrap.each_line do |line|
      line " %-#{label_width}s %s" % [label, line]
      label = ''
    end
  end
end
add_text(content) click to toggle source
# File lib/hammer_cli/help/builder.rb, line 55
def add_text(content)
  line
  line content
end
add_usage(invocation_path, usage_descriptions) click to toggle source
# File lib/hammer_cli/help/builder.rb, line 13
def add_usage(invocation_path, usage_descriptions)
  heading(Clamp.message(:usage_heading))
  usage_descriptions.each do |usage|
    line "    #{HammerCLI.expand_invocation_path(invocation_path)} #{usage}".rstrip
  end
end

Protected Instance Methods

heading(label) click to toggle source
# File lib/hammer_cli/help/builder.rb, line 62
def heading(label)
  label = "#{label}:"
  label = HighLine.color(label, :bold) if @richtext
  line label
end