class Clamp::Help::Builder

A builder for auto-generated help.

Constants

DETAIL_FORMAT

Attributes

lines[RW]

Public Class Methods

new() click to toggle source
# File lib/clamp/help.rb, line 58
def initialize
  @lines = []
end

Public Instance Methods

add_description(description) click to toggle source
# File lib/clamp/help.rb, line 93
def add_description(description)
  return unless description
  line
  line description.gsub(/^/, "  ")
end
add_list(heading, items) click to toggle source
# File lib/clamp/help.rb, line 101
def add_list(heading, items)
  line
  line "#{heading}:"
  items.reject { |i| i.respond_to?(:hidden?) && i.hidden? }.each do |item|
    label, description = item.help
    description.each_line do |line|
      row(label, line)
      label = ""
    end
  end
end
add_usage(invocation_path, usage_descriptions) click to toggle source
# File lib/clamp/help.rb, line 86
def add_usage(invocation_path, usage_descriptions)
  line Clamp.message(:usage_heading) + ":"
  usage_descriptions.each do |usage|
    line "    #{invocation_path} #{usage}".rstrip
  end
end
line(text = "") click to toggle source
# File lib/clamp/help.rb, line 78
def line(text = "")
  @lines << text
end
row(lhs, rhs) click to toggle source
# File lib/clamp/help.rb, line 82
def row(lhs, rhs)
  @lines << [lhs, rhs]
end
string() click to toggle source
# File lib/clamp/help.rb, line 62
def string
  left_column_width = lines.grep(Array).map(&:first).map(&:size).max
  StringIO.new.tap do |out|
    lines.each do |line|
      case line
      when Array
        line[0] = line[0].ljust(left_column_width)
        line.unshift("")
        out.puts(line.join("    "))
      else
        out.puts(line)
      end
    end
  end.string
end