Module: Cuprum::Cli::Arguments::ClassMethods
- Parent Namespace
- Cuprum::Cli::Arguments
- Defined In
- lib/cuprum/cli/arguments/class_methods.rb
Table Of Contents
Overview
Methods used to extend command class functionality for defining arguments.
Back To Top
Defined Under Namespace
- Classes
- Builder
Back To Top
Instance Methods
#argument(name, default: nil, description: nil, required: false, type: :string, variadic: false, **options) => Object
Defines an argument for the command class.
Parameters
- name (String, Symbol) — the name of the argument.
- default (Object, Proc) — the default value for the argument. If
given and the value of the argument is nil, sets the argument value to
the default value.
- description (String) — a short, human-readable description of the
argument.
- required (true, false) — if true, raises an exception if the
argument is not provided to the command. Defaults to false.
- type (Class, String, Symbol) — the expected type of the argument
value as a Class or class name. If given, raises an exception if the
argument value is not an instance of the type. Defaults to :string.
- variadic (true, false) — if true, the argument is variadic and
represents an array of arguments provided to the command. Defaults to
false.
- options (Hash) — additional options for defining the argument.
Options Hash (options)
- define_method (true, false) — if true, defines a reader
method for the argument. Defaults to false for boolean arguments and
true for all other arguments.
- define_predicate (true, false) — if true, defines a
predicate method for the argument, which returns true if the argument
is not nil and not empty. Defaults to true for boolean arguments and
false for all other arguments.
Raises
- (ArgumentError) — if variadic is true and the command already
defines a variadic argument.
#argument_value(value) => void
Appends a predefined argument value for the command.
Parameters
- value (Object) — the argument value to append.
Returns
#argument_values => Array<Object>
Returns
- (Array<Object>) — predefined argument values for the command.
#arguments() => Array<Cuprum::Cli::Argument>
#arguments(name, default: nil, description: nil, required: false, type: :string, **options) => Object
Overloads
The defined arguments for the command class.
Returns
#arguments(name, default: nil, description: nil, required: false, type: :string, **options) => Object
Defines a variadic argument for the command class.
Parameters
- name (String, Symbol) — the name of the argument.
- default (Object, Proc) — the default value for the argument. If
given and the value of the argument is nil, sets the argument value to
the default value.
- description (String) — a short, human-readable description of the
argument.
- required (true, false) — if true, raises an exception if the
argument is not provided to the command.
- type (Class, String, Symbol) — the expected type of the argument
value as a Class or class name. If given, raises an exception if the
argument value is not an instance of the type. Defaults to :string.
- options (Hash) — additional options for defining the argument.
Options Hash (options)
- define_method (true, false) — if true, defines a reader
method for the argument. Defaults to false for boolean arguments and
true for all other arguments.
- define_predicate (true, false) — if true, defines a
predicate method for the argument, which returns true if the argument
is not nil and not empty. Defaults to true for boolean arguments and
false for all other arguments.
#resolve_arguments(*values) => Array
Validates the given argument values against the defined class arguments.
Also applies any default values from the defined arguments.
Parameters
- values (Array) — the arguments values to resolve.
Returns
- (Array) — the arguments values with applied defaults.
Raises
Back To Top
Back to
Documentation |
Reference
|
Cuprum
|
Cuprum::Cli
|
Cuprum::Cli::Arguments