Class: Cuprum::Cli::Options::ClassMethods::Builder
- Parent Namespace
- Cuprum::Cli::Options::ClassMethods
- Defined In
- lib/cuprum/cli/options/class_methods.rb
Table Of Contents
Overview
Helper class for defining command options.
Back To Top
Constructor
#initialize(command_class:, defined_options:) => Builder
Parameters
- command_class (Class) — the command class.
- defined_options (Hash{Symbol => Cuprum::Cli::Option}) — the options
defined for the command.
Returns
- (Builder) — a new instance of Builder
Back To Top
Instance Attributes
#command_class => Class (readonly)
Returns
- (Class) — the command class.
#defined_options => Hash{Symbol => Cuprum::Cli::Option} (readonly)
Returns
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.
Back To Top
Back to
Documentation |
Reference
|
Cuprum
|
Cuprum::Cli
|
Cuprum::Cli::Options
|
Cuprum::Cli::Options::ClassMethods