Class: Clamp::Help::Builder

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

Overview

A builder for auto-generated help.

Constant Summary collapse

DETAIL_FORMAT =
"    %-29s %s".freeze

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



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

def initialize
  @out = StringIO.new
end

Instance Method Details

#add_description(description) ⇒ Object



73
74
75
76
77
# File 'lib/clamp/help.rb', line 73

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

#add_list(heading, items) ⇒ Object



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

def add_list(heading, items)
  puts "\n#{heading}:"
  items.reject { |i| i.respond_to?(:hidden?) && i.hidden? }.each do |item|
    label, description = item.help
    description.each_line do |line|
      puts format(DETAIL_FORMAT, label, line)
      label = ""
    end
  end
end

#add_usage(invocation_path, usage_descriptions) ⇒ Object



66
67
68
69
70
71
# File 'lib/clamp/help.rb', line 66

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

#stringObject



62
63
64
# File 'lib/clamp/help.rb', line 62

def string
  @out.string
end