Class: Clamp::Help::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/clamp/help.rb

Constant Summary collapse

DETAIL_FORMAT =
"    %-29s %s"

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



55
56
57
# File 'lib/clamp/help.rb', line 55

def initialize
  @out = StringIO.new
end

Instance Method Details

#add_description(description) ⇒ Object



70
71
72
73
74
75
# File 'lib/clamp/help.rb', line 70

def add_description(description)
  if description
    puts ""
    puts description.gsub(/^/, "  ")
  end
end

#add_list(heading, items) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/clamp/help.rb', line 79

def add_list(heading, items)
  puts "\n#{heading}:"
  items.each do |item|
    label, description = item.help
    description.each_line do |line|
      puts DETAIL_FORMAT % [label, line]
      label = ''
    end
  end
end

#add_usage(invocation_path, usage_descriptions) ⇒ Object



63
64
65
66
67
68
# File 'lib/clamp/help.rb', line 63

def add_usage(invocation_path, usage_descriptions)
  puts "Usage:"
  usage_descriptions.each do |usage|
    puts "    #{invocation_path} #{usage}".rstrip
  end
end

#stringObject



59
60
61
# File 'lib/clamp/help.rb', line 59

def string
  @out.string
end