Class: Cuprum::Cli::Option
- Parent Namespace
- Cuprum::Cli
- Inherited Classes
- Data
>
Object
- Defined In
- lib/cuprum/cli/option.rb
Table Of Contents
Overview
Data object representing a command option.
Back To Top
Constructor
#initialize(name:, aliases: [], default: nil, description: nil, parameter_name: nil, required: false, type: :string, variadic: false) => Option
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.
- parameter_name (String) — a representation of the possible values for
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.
- variadic (true, false) — if true, the option is variadic and
represents an hash of options provided to the command. Defaults to
false.
Returns
- (Option) — a new instance of Option
Back To Top
Instance Attributes
#aliases => Object (readonly)
Returns the value of attribute aliases
Returns
- (Object) — the current value of aliases
#default => Object (readonly)
Returns the value of attribute default
Returns
- (Object) — the current value of default
#description => Object (readonly)
Returns the value of attribute description
Returns
- (Object) — the current value of description
#name => Object (readonly)
Returns the value of attribute name
Returns
- (Object) — the current value of name
#parameter_name => Object (readonly)
Returns the value of attribute parameter_name
Returns
- (Object) — the current value of parameter_name
#required => Object (readonly)
Also known as:
required?
Returns the value of attribute required
Returns
- (Object) — the current value of required
#type => Object (readonly)
Returns the value of attribute type
Returns
- (Object) — the current value of type
#variadic => Object (readonly)
Also known as:
variadic?
Returns the value of attribute variadic
Returns
- (Object) — the current value of variadic
Back To Top
Instance Methods
#resolve(value) => Object
Overloads
#resolve(value) => Object
Validates the value for the current option.
If the value is nil, applies the option default (if any).
Parameters
- value (Object) — the value to validate.
Returns
- (Object) — the validated option value.
Raises
Raises
Back To Top
Back to
Documentation |
Reference
|
Cuprum
|
Cuprum::Cli