Method: Mixlib::CLI::ClassMethods#deprecated_option

Defined in:
lib/mixlib/cli.rb

#deprecated_option(name, replacement: nil, long: nil, short: nil, boolean: false, value_mapper: nil, keep: true) ⇒ Object

Declare a deprecated option

Add a deprecated command line option.

name<Symbol>

The name of the deprecated option

replacement<Symbol>

The name of the option that replaces this option.

long<String>

The original long flag name, or flag name with argument, eg “–user USER”

short<String>

The original short-form flag name, eg “-u USER”

boolean<String>

true if this is a boolean flag, eg “–[no-]option”.

value_mapper<Proc/1>

a block that accepts the original value from the deprecated option,

and converts it to a value suitable for the new option.
If not provided, the value provided to the deprecated option will be
assigned directly to the converted option.
keep<Boolean>

Defaults to true, this ensures that options[:deprecated_flag] is populated when the deprecated flag is used. If set to false, only the value in replacement will be set. Results undefined if no replacement is provided. You can use this to enforce the transition to non-deprecated keys in your code.

Returns

<Hash>

The config hash for the created option.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/mixlib/cli.rb', line 151

def deprecated_option(name,
  replacement: nil,
  long: nil,
  short: nil,
  boolean: false,
  value_mapper: nil,
  keep: true)

  description = if replacement
                  replacement_cfg = options[replacement]
                  display_name = CLI::Formatter.combined_option_display_name(replacement_cfg[:short], replacement_cfg[:long])
                  "This flag is deprecated. Use #{display_name} instead."
                else
                  "This flag is deprecated and will be removed in a future release."
                end
  value_mapper ||= Proc.new { |v| v }

  option(name,
    long: long,
    short: short,
    boolean: boolean,
    description: description,
    on: :tail,
    deprecated: true,
    keep: keep,
    replacement: replacement,
    value_mapper: value_mapper)
end