Module Mixlib::CLI
In: lib/mixlib/cli/version.rb
lib/mixlib/cli.rb

Mixlib::CLI

Adds a DSL for defining command line options and methods for parsing those options to the including class.

Mixlib::CLI does some setup in initialize, so the including class must call `super()` if it defines a custom initializer.

DSL

When included, Mixlib::CLI also extends the including class with its ClassMethods, which define the DSL. The primary methods of the DSL are ClassMethods#option, which defines a command line option, and ClassMethods#banner, which defines the "usage" banner.

Parsing

Command line options are parsed by calling the instance method parse_options. After calling this method, the attribute config will contain a hash of `:option_name => value` pairs.

Methods

Classes and Modules

Module Mixlib::CLI::ClassMethods
Module Mixlib::CLI::InheritMethods

Constants

VERSION = "1.7.0"

Attributes

banner  [RW]  Banner for the option parser. If the option parser is printed, e.g., by `puts opt_parser`, this string will be used as the first line.
cli_arguments  [RW]  Any arguments which were not parsed and placed in "config"—the leftovers.
config  [RW]  A Hash containing the values supplied by command line options.

The behavior and contents of this Hash vary depending on whether ClassMethods#use_separate_default_options is enabled.

use_separate_default_options disabled

After initialization, config will contain any default values defined via the mixlib-config DSL. When parse_options is called, user-supplied values (from ARGV) will be merged in.

use_separate_default_options enabled

After initialization, this will be an empty hash. When parse_options is called, config is populated only with user-supplied values.

default_config  [RW]  If ClassMethods#use_separate_default_options is enabled, this will be a Hash containing key value pairs of `:option_name => default_value` (populated during object initialization).

If use_separate_default_options is disabled, it will always be an empty hash.

options  [RW]  Gives the command line options definition as configured in the DSL. These are used by parse_options to generate the option parsing code. To get the values supplied by the user, see config.

Public Class methods

Create a new Mixlib::CLI class. If you override this, make sure you call super!

Parameters

*args<Array>:The array of arguments passed to the initializer

Returns

object<Mixlib::Config>:Returns an instance of whatever you wanted :)

Public Instance methods

The option parser generated from the mixlib-cli DSL. opt_parser can be used to print a help message including the banner and any CLI options via `puts opt_parser`.

Returns

opt_parser<OptionParser>:The option parser object.

Parses an array, by default ARGV, for command line options (as configured at the class level).

Parameters

argv<Array>:The array of arguments to parse; defaults to ARGV

Returns

argv<Array>:Returns any un-parsed elements.

[Validate]