Class: Mixlib::CLI::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlib/cli/formatter.rb

Class Method Summary collapse

Class Method Details

.combined_option_display_name(short, long) ⇒ String

Create a string that includes both versions (short/long) of a flag name based on on whether short/long/both/neither are provided

Parameters:

  • short (String)

    the short name of the option. Can be nil.

  • long (String)

    the long name of the option. Can be nil.

Returns:

  • (String)

    the formatted flag name as described above


11
12
13
14
15
16
17
18
19
20
# File 'lib/mixlib/cli/formatter.rb', line 11

def self.combined_option_display_name(short, long)
  usage = ""
  # short/long may have an argument (--long ARG)
  # splitting on " " and taking first ensures that we get just
  # the flag name without the argument if one is present.
  usage << short.split(" ").first if short
  usage << "/" if long && short
  usage << long.split(" ").first if long
  usage
end

.friendly_opt_list(opt_array) ⇒ String

Returns a friendly quoted list of items complete with “or”.

Parameters:

  • opt_array (Array)

Returns:

  • (String)

    a friendly quoted list of items complete with “or”


25
26
27
28
29
30
# File 'lib/mixlib/cli/formatter.rb', line 25

def self.friendly_opt_list(opt_array)
  opts = opt_array.map { |x| "'#{x}'" }
  return opts.join(" or ") if opts.size < 3

  opts[0..-2].join(", ") + ", or " + opts[-1]
end