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



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_separatorObject



35
36
37
# File 'lib/eac_cli/runner_with/help/builder.rb', line 35

def word_separator
  WORD_SEPARATOR
end

Instance Method Details

#definitionObject



42
43
44
# File 'lib/eac_cli/runner_with/help/builder.rb', line 42

def definition
  runner.class.runner_definition
end

#extra_sectionsEnumerable<String>

Returns:

  • (Enumerable<String>)


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

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

Returns:

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

#to_sObject



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

#usage_sectionString

Returns:

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