Class: EacCli::Runner::DocoptDoc
- Inherits:
-
Object
- Object
- EacCli::Runner::DocoptDoc
- Defined in:
- lib/eac_cli/runner/docopt_doc.rb
Constant Summary collapse
Instance Method Summary collapse
- #option_argument(option) ⇒ Object
- #option_definition(option) ⇒ Object
- #option_long(option) ⇒ Object
- #positional_argument(positional) ⇒ Object
- #section(header, include_header = true) ⇒ Object
- #self_options ⇒ Object
- #self_usage ⇒ Object
- #self_usage_arguments ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#option_argument(option) ⇒ Object
21 22 23 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 21 def option_argument(option) option_long(option) end |
#option_definition(option) ⇒ Object
25 26 27 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 25 def option_definition(option) option.short + SEP + option_long(option) + OPTION_DESC_SEP + option.description end |
#option_long(option) ⇒ Object
29 30 31 32 33 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 29 def option_long(option) b = option.long b += '=<value>' if option.argument? b end |
#positional_argument(positional) ⇒ Object
15 16 17 18 19 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 15 def positional_argument(positional) r = "<#{positional.name}>" r += '...' if positional.repeat? r end |
#section(header, include_header = true) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 35 def section(header, include_header = true) b = include_header ? "#{header.humanize}:\n" : '' b += send("self_#{header}") + "\n" definition.alternatives.each do |alternative| b += self.class.new(alternative).section(header, false) end b end |
#self_options ⇒ Object
44 45 46 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 44 def definition..map { |option| IDENT + option_definition(option) }.join("\n") end |
#self_usage ⇒ Object
48 49 50 51 52 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 48 def self_usage b = IDENT + ::EacRubyUtils::Console::DocoptRunner::PROGRAM_MACRO b += "#{SEP}[options]" if definition. b + self_usage_arguments end |
#self_usage_arguments ⇒ Object
54 55 56 57 58 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 54 def self_usage_arguments definition..select(&:show_on_usage?) .map { |option| "#{SEP}#{option_argument(option)}" }.join + definition.positional.map { |p| "#{SEP}#{positional_argument(p)}" }.join end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/eac_cli/runner/docopt_doc.rb', line 60 def to_s "#{definition.description}\n\n#{section('usage')}\n#{section('options')}\n" end |