Module: Cuprum::Cli::Options::ClassMethods
- Parent Namespace
- Cuprum::Cli::Options
- Defined In
- lib/cuprum/cli/options/class_methods.rb
Table Of Contents
Overview
Methods used to extend command class functionality for defining options.
Back To Top
Defined Under Namespace
- Classes
- Builder
Back To Top
Instance Methods
#option(name, aliases: [], default: nil, description: nil, required: false, type: :string, **options) => Object
Defines an option for the command class.
Parameters
- name (String, Symbol) — the name of the option.
- aliases (Array<String, Symbol>) — aliases for the option when
parsing options from the command line.
- default (Object, Proc) — the default value for the option. If given
and the value of the option is nil, sets the option value to the
default value.
- description (String) — a short, human-readable description of the
option.
- required (true, false) — if true, raises an exception if the option
is not provided to the command.
- type (Class, String, Symbol) — the expected type of the option
value as a Class or class name. If given, raises an exception if the
option value is not an instance of the type. Defaults to :string.
- options (Hash) — additional options for defining the option.
Options Hash (options)
- define_method (true, false) — if true, defines a reader
method for the option. Defaults to false for boolean options and true
for all other options.
- define_predicate (true, false) — if true, defines a
predicate method for the option, which returns true if the option is
not nil and not empty. Defaults to true for boolean options and false
for all other options.
#option_value(option, value) => void
Assigns a predefined option value for the command.
Parameters
- option (String, Symbol) — the option to set.
- value (Object) — the option value to append.
Returns
#option_values => Hash{Symbol => Object}
Returns
- (Hash{Symbol => Object}) — predefined option values for the command.
The defined options, including options defined on ancestor classes.
Returns
#resolve_options(**values) => Hash
Validates the given option values against the defined class options.
Also applies any default values from the defined options.
Parameters
- values (Hash) — the option values to resolve.
Returns
- (Hash) — the option values with applied defaults.
Raises
Back To Top
Back to
Documentation |
Reference
|
Cuprum
|
Cuprum::Cli
|
Cuprum::Cli::Options