diff options
Diffstat (limited to 'lib/mixlib/cli')
-rw-r--r-- | lib/mixlib/cli/formatter.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/mixlib/cli/formatter.rb b/lib/mixlib/cli/formatter.rb new file mode 100644 index 0000000..b89090d --- /dev/null +++ b/lib/mixlib/cli/formatter.rb @@ -0,0 +1,29 @@ + +module Mixlib + module CLI + class Formatter + # Create a string that includes both versions (short/long) of a flag name + # based on on whether short/long/both/neither are provided + # + # @param short [String] the short name of the option. Can be nil. + # @param long [String] the long name of the option. Can be nil. + # @return [String] the formatted flag name as described above + def self.combined_option_display_name(short, long) + usage = "" + usage << short.split(" ").first if short + usage << "/" if long && short + usage << long.split(" ").first if long + usage + end + + # @param opt_arry [Array] + # + # @return [String] a friendly quoted list of items complete with "or" + 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 + end + end +end |