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
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
- #option_definition(option) ⇒ Object
- #options_section ⇒ Object
- #section(header, include_header = true) ⇒ Object
- #to_s ⇒ Object
- #usage_section ⇒ Object
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 |
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 |
#option_definition(option) ⇒ Object
48 49 50 51 52 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 48 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 ⇒ Object
63 64 65 66 67 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 63 def "Options:\n" + definition.alternatives.flat_map(&:options) .map { |option| IDENT + option_definition(option) + "\n" }.join end |
#section(header, include_header = true) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 54 def section(header, include_header = true) b = include_header ? "#{header.humanize}:\n" : '' b += send("self_#{header}") + "\n" definition.alternatives.each do |alternative| b += IDENT + self.alternative(alternative) + "\n" end b end |
#to_s ⇒ Object
76 77 78 |
# File 'lib/eac_cli/runner_with/help/builder.rb', line 76 def to_s "#{definition.description}\n\n#{usage_section}\n#{}\n" end |