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
15
16
17
18
19
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 15
def option_long(option)
b = option.long
b += '=<value>' if option.argument?
b
end
|
.option_short(option) ⇒ Object
21
22
23
24
25
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 21
def option_short(option)
b = option.short
b += '=<value>' if option.argument?
b
end
|
.option_usage_full(option) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 27
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
35
36
37
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 35
def word_separator
WORD_SEPARATOR
end
|
Instance Method Details
#definition ⇒ Object
42
43
44
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 42
def definition
runner.class.runner_definition
end
|
47
48
49
50
51
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 47
def
runner.if_respond(:help_extra_text, []) do |v|
[v.to_s]
end
end
|
#option_definition(option) ⇒ Object
53
54
55
56
57
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 53
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
60
61
62
63
64
65
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 60
def options_section
list_section(
'Options',
definition.alternatives.flat_map(&:options).map { |option| option_definition(option) }
)
end
|
75
76
77
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 75
def to_s
join_sections(definition.description, usage_section, options_section, *)
end
|
#usage_section ⇒ String
68
69
70
71
72
73
|
# File 'lib/eac_cli/runner_with/help/builder.rb', line 68
def usage_section
list_section(
'Usage',
definition.alternatives.map { |alternative| self.alternative(alternative) }
)
end
|