Class: EacCli::RunnerWith::Help::Builder
- Inherits:
-
Object
- Object
- EacCli::RunnerWith::Help::Builder
show all
- Includes:
- Layout
- 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
Layout::InstanceClassMethods::IDENTATION, Layout::InstanceClassMethods::LINE_BREAK, Layout::InstanceClassMethods::OPTION_DESCRIPTION_SEPARATOR, Layout::InstanceClassMethods::SECTION_SEPARATOR, Layout::InstanceClassMethods::WORD_SEPARATOR
Class Method Summary
collapse
Instance Method Summary
collapse
#join_sections, #list_section
Class Method Details
.option_long(option) ⇒ Object
13
14
15
16
17
|
# File 'lib/eac_cli/runner_with/help/builder.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/runner_with/help/builder.rb', line 19
def option_short(option)
b = option.short
b += '=<value>' if option.argument?
b
end
|
.option_usage_full(option) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 25
def option_usage_full(option)
if option.long.present?
[option.short, option_long(option)].compact_blank.join(word_separator)
else
option_short(option)
end
end
|
.word_separator ⇒ Object
33
34
35
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 33
def word_separator
WORD_SEPARATOR
end
|
Instance Method Details
#definition ⇒ Object
40
41
42
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 40
def definition
runner.class.runner_definition
end
|
45
46
47
48
49
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 45
def
runner.if_respond(:help_extra_text, []) do |v|
[v.to_s]
end
end
|
#option_definition(option) ⇒ Object
51
52
53
54
55
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 51
def option_definition(option)
[self.class.option_usage_full(option), option.description,
option.default_value? ? "[Default: \"#{option.default_value}\"]" : nil]
.compact_blank.join(OPTION_DESCRIPTION_SEPARATOR)
end
|
#options_section ⇒ String
58
59
60
61
62
63
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 58
def options_section
list_section(
'Options',
definition.alternatives.flat_map(&:options).map { |option| option_definition(option) }
)
end
|
73
74
75
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 73
def to_s
join_sections(definition.description, usage_section, options_section, *)
end
|
#usage_section ⇒ String
66
67
68
69
70
71
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 66
def usage_section
list_section(
'Usage',
definition.alternatives.map { |alternative| self.alternative(alternative) }
)
end
|