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
12
13
14
15
16
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 12
def option_long(option)
b = option.long
b += '=<value>' if option.argument?
b
end
|
.option_short(option) ⇒ Object
18
19
20
21
22
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 18
def option_short(option)
b = option.short
b += '=<value>' if option.argument?
b
end
|
.option_usage_full(option) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 24
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
32
33
34
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 32
def word_separator
WORD_SEPARATOR
end
|
Instance Method Details
#definition ⇒ Object
39
40
41
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 39
def definition
runner.class.runner_definition
end
|
44
45
46
47
48
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 44
def
runner.if_respond(:help_extra_text, []) do |v|
[v.to_s]
end
end
|
#option_definition(option) ⇒ Object
50
51
52
53
54
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 50
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
57
58
59
60
61
62
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 57
def options_section
list_section(
'Options',
definition.alternatives.flat_map(&:options).map { |option| option_definition(option) }
)
end
|
72
73
74
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 72
def to_s
join_sections(definition.description, usage_section, options_section, *)
end
|
#usage_section ⇒ String
65
66
67
68
69
70
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 65
def usage_section
list_section(
'Usage',
definition.alternatives.map { |alternative| self.alternative(alternative) }
)
end
|