Class: EacCli::RunnerWith::Help::Builder

Inherits:
Object
  • Object
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

Constants included from Layout::InstanceClassMethods

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

Methods included from Layout::InstanceClassMethods

#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_separatorObject



33
34
35
# File 'lib/eac_cli/runner_with/help/builder.rb', line 33

def word_separator
  WORD_SEPARATOR
end

Instance Method Details

#definitionObject



40
41
42
# File 'lib/eac_cli/runner_with/help/builder.rb', line 40

def definition
  runner.class.runner_definition
end

#extra_sectionsEnumerable<String>

Returns:

  • (Enumerable<String>)


45
46
47
48
49
# File 'lib/eac_cli/runner_with/help/builder.rb', line 45

def extra_sections
  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_sectionString

Returns:

  • (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

#to_sObject



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, *extra_sections)
end

#usage_sectionString

Returns:

  • (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