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

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_cli/runner_with/help/builder/alternative.rb

Constant Summary collapse

PROGRAM_MACRO =
'__PROGRAM__'
SUBCOMMANDS_MACRO =
'__SUBCOMMANDS__'

Instance Method Summary collapse

Instance Method Details

#option_argument(option) ⇒ Object



30
31
32
33
34
# File 'lib/eac_cli/runner_with/help/builder/alternative.rb', line 30

def option_argument(option)
  b = option.long
  b += '=<value>' if option.argument?
  b
end

#optionsObject



24
25
26
27
28
# File 'lib/eac_cli/runner_with/help/builder/alternative.rb', line 24

def options
  alternative.options.select(&:show_on_usage?).map do |option|
    ::EacCli::RunnerWith::Help::Builder.option_long(option)
  end
end

#positional(positional) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/eac_cli/runner_with/help/builder/alternative.rb', line 40

def positional(positional)
  return unless positional.visible?

  if positional.subcommand?
    SUBCOMMANDS_MACRO
  else
    r = "<#{positional.name}>"
    r += '...' if positional.repeat?
    r = "[#{r}]" if positional.optional?
    r
  end
end

#positionalsObject



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

def positionals
  alternative.positional.map { |p| positional(p) }.reject(&:blank?)
end

#to_sObject



15
16
17
18
19
20
21
22
# File 'lib/eac_cli/runner_with/help/builder/alternative.rb', line 15

def to_s
  (
    [PROGRAM_MACRO] +
      alternative.options_argument?.if_present([]) { |_v| ['[options]'] } +
      options +
      positionals
  ).join(::EacCli::RunnerWith::Help::Builder::SEP)
end