Class: EacCli::RunnerWith::Help::Builder
- Defined in:
- lib/eac_cli/runner_with/help/builder.rb,
lib/eac_cli/runner_with/help/builder/alternative.rb
Defined Under Namespace
Classes: Alternative
Constant Summary collapse
- OPTION_DESC_SEP =
::EacCli::RunnerWith::Help::ListSection::IDENTATION * 2
- SECTION_SEPARATOR =
"\n"
Class Method Summary collapse
- .option_long(option) ⇒ Object
- .option_short(option) ⇒ Object
- .option_usage_full(option) ⇒ Object
- .word_separator ⇒ Object
Instance Method Summary collapse
- #definition ⇒ Object
- #extra_section ⇒ String?
- #extra_sections ⇒ Enumerable<String>
- #option_definition(option) ⇒ Object
- #options_section ⇒ String
- #to_s ⇒ Object
- #usage_section ⇒ String
Class Method Details
.option_long(option) ⇒ Object
17 18 19 20 21 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 17 def option_long(option) b = option.long b += '=<value>' if option.argument? b end |
.option_short(option) ⇒ Object
23 24 25 26 27 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 23 def option_short(option) b = option.short b += '=<value>' if option.argument? b end |
.option_usage_full(option) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 29 def option_usage_full(option) if option.long.present? [option.short, option_long(option)].reject(&:blank?).join(word_separator) else option_short(option) end end |
.word_separator ⇒ Object
37 38 39 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 37 def word_separator ::EacCli::RunnerWith::Help::ListSection::WORD_SEPARATOR end |
Instance Method Details
#definition ⇒ Object
44 45 46 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 44 def definition runner.class.runner_definition end |
#extra_section ⇒ String?
49 50 51 52 53 54 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 49 def extra_section ess = extra_sections return nil if ess.none? ess.join(SECTION_SEPARATOR) end |
#extra_sections ⇒ Enumerable<String>
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 57 def extra_sections runner.if_respond(:help_extra_text, []) do |v| if v.is_a?(::Hash) v.map do |title, lines| ::EacCli::RunnerWith::Help::ListSection.new(title, lines) end else [v.to_s] end end end |
#option_definition(option) ⇒ Object
69 70 71 72 73 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 69 def option_definition(option) [self.class.option_usage_full(option), option.description, option.default_value? ? "[Default: \"#{option.default_value}\"]" : nil] .reject(&:blank?).join(OPTION_DESC_SEP) end |
#options_section ⇒ String
76 77 78 79 80 81 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 76 def ::EacCli::RunnerWith::Help::ListSection.new( 'Options', definition.alternatives.flat_map(&:options).map { |option| option_definition(option) } ) end |
#to_s ⇒ Object
91 92 93 94 95 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 91 def to_s r = ["#{definition.description}\n", usage_section, ] .map { |s| "#{s}#{SECTION_SEPARATOR}" }.join extra_section.if_present(r) { |v| r + v } end |
#usage_section ⇒ String
84 85 86 87 88 89 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 84 def usage_section ::EacCli::RunnerWith::Help::ListSection.new( 'Usage', definition.alternatives.map { |alternative| self.alternative(alternative) } ) end |