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.



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

def initialize
  @out = StringIO.new
end

Instance Method Details

#add_description(description) ⇒ Object



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

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

#add_list(heading, items) ⇒ Object



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

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 DETAIL_FORMAT % [label, line]
      label = ''
    end
  end
end

#add_usage(invocation_path, usage_descriptions) ⇒ Object



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

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



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

def string
  @out.string
end