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

SUBCOMMANDS_MACRO =
'__SUBCOMMANDS__'

Instance Method Summary collapse

Instance Method Details

#option_argument(option) ⇒ Object



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

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

#optionsObject



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

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

#positional(positional) ⇒ Object



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

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



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

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

#program_nameObject



54
55
56
57
58
# File 'lib/eac_cli/runner_with/help/builder/alternative.rb', line 54

def program_name
  r = builder.runner.program_name
  r = [r] unless r.is_a?(::Enumerable)
  r
end

#resultObject



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

def result
  (
    program_name +
      alternative.options_argument?.if_present([]) { |_v| ['[options]'] } +
      options +
      positionals
  ).join(builder.word_separator)
end