Class: HammerCLI::Help::Builder
- Inherits:
-
Clamp::Help::Builder
- Object
- Clamp::Help::Builder
- HammerCLI::Help::Builder
- Defined in:
- lib/hammer_cli/help/builder.rb
Constant Summary collapse
- DEFAULT_LABEL_INDENT =
29
Instance Attribute Summary collapse
-
#richtext ⇒ Object
readonly
Returns the value of attribute richtext.
Instance Method Summary collapse
- #add_list(heading, items) ⇒ Object
- #add_text(content) ⇒ Object
- #add_usage(invocation_path, usage_descriptions) ⇒ Object
-
#initialize(richtext = false) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(richtext = false) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 |
# File 'lib/hammer_cli/help/builder.rb', line 9 def initialize(richtext = false) super() @richtext = richtext end |
Instance Attribute Details
#richtext ⇒ Object (readonly)
Returns the value of attribute richtext.
7 8 9 |
# File 'lib/hammer_cli/help/builder.rb', line 7 def richtext @richtext end |
Instance Method Details
#add_list(heading, items) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/hammer_cli/help/builder.rb', line 21 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?} puts heading(heading) label_width = DEFAULT_LABEL_INDENT items.each do |item| label = item.help.first 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.switch, item.family.description || item.help[1]] else item.help end description.gsub(/^(.)/) { Unicode::capitalize($1) }.each_line do |line| puts " %-#{label_width}s %s" % [label, line] label = '' end end end |
#add_text(content) ⇒ Object
52 53 54 55 |
# File 'lib/hammer_cli/help/builder.rb', line 52 def add_text(content) puts puts content end |
#add_usage(invocation_path, usage_descriptions) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/hammer_cli/help/builder.rb', line 14 def add_usage(invocation_path, usage_descriptions) heading(Clamp.(:usage_heading)) usage_descriptions.each do |usage| puts " #{HammerCLI.(invocation_path)} #{usage}".rstrip end end |