Class: EacCli::Definition::HelpFormatter
- Defined in:
- lib/eac_cli/definition/help_formatter.rb
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #positional_argument(positional) ⇒ Object
- #section(header, include_header = true) ⇒ Object
- #self_options ⇒ Object
- #self_usage ⇒ Object
- #self_usage_arguments ⇒ Object
- #self_usage_arguments_options ⇒ Object
- #self_usage_arguments_positional ⇒ Object
- #to_banner ⇒ Object
Class Method Details
.option_long(option) ⇒ Object
13 14 15 16 17 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 13 def option_long(option) b = option.long b += '=VALUE' if option.argument? b end |
.option_short(option) ⇒ Object
19 20 21 22 23 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 19 def option_short(option) b = option.short b += 'VALUE' if option.argument? b end |
Instance Method Details
#positional_argument(positional) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 28 def positional_argument(positional) if positional.subcommand? ::EacCli::DocoptRunner::SUBCOMMANDS_MACRO else r = "<#{positional.name}>" r += '...' if positional.repeat? r = "[#{r}]" if positional.optional? r end end |
#section(header, include_header = true) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 39 def section(header, include_header = true) b = include_header ? "#{header.humanize}:\n" : '' b += send("self_#{header}") + "\n" # TO-DO: implement alternatives b end |
#self_options ⇒ Object
46 47 48 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 46 def definition..map { |option| IDENT + option_definition(option) }.join("\n") end |
#self_usage ⇒ Object
50 51 52 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 50 def self_usage IDENT + self_usage_arguments.join(SEP) end |
#self_usage_arguments ⇒ Object
54 55 56 57 58 59 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 54 def self_usage_arguments [::EacCli::DocoptRunner::PROGRAM_MACRO] + definition..if_present([]) { |_v| ['[options]'] } + + self_usage_arguments_positional end |
#self_usage_arguments_options ⇒ Object
61 62 63 64 65 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 61 def definition..select(&:show_on_usage?).map do |option| self.class.option_long(option) end end |
#self_usage_arguments_positional ⇒ Object
67 68 69 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 67 def self_usage_arguments_positional definition.positional.map { |p| positional_argument(p) } end |
#to_banner ⇒ Object
71 72 73 |
# File 'lib/eac_cli/definition/help_formatter.rb', line 71 def "#{definition.description}\n\n#{section('usage')}" end |