Class: Cuprum::Cli::Arguments::ClassMethods::Builder
- Inherits:
-
Object
- Object
- Cuprum::Cli::Arguments::ClassMethods::Builder
- Defined in:
- lib/cuprum/cli/arguments/class_methods.rb
Overview
Helper class for defining command arguments.
Instance Attribute Summary collapse
-
#command_class ⇒ Class
readonly
The command class.
-
#defined_arguments ⇒ Array<Cuprum::Cli::Argument>
readonly
The arguments defined for the command.
Instance Method Summary collapse
-
#argument(name, default: nil, description: nil, required: false, type: :string, variadic: false, **options) ⇒ Object
Defines an argument for the command class.
-
#initialize(command_class:, defined_arguments:) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(command_class:, defined_arguments:) ⇒ Builder
Returns a new instance of Builder.
15 16 17 18 |
# File 'lib/cuprum/cli/arguments/class_methods.rb', line 15 def initialize(command_class:, defined_arguments:) @command_class = command_class @defined_arguments = defined_arguments end |
Instance Attribute Details
#command_class ⇒ Class (readonly)
Returns the command class.
21 22 23 |
# File 'lib/cuprum/cli/arguments/class_methods.rb', line 21 def command_class @command_class end |
#defined_arguments ⇒ Array<Cuprum::Cli::Argument> (readonly)
Returns the arguments defined for the command.
25 26 27 |
# File 'lib/cuprum/cli/arguments/class_methods.rb', line 25 def defined_arguments @defined_arguments end |
Instance Method Details
#argument(name, default: nil, description: nil, required: false, type: :string, variadic: false, **options) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cuprum/cli/arguments/class_methods.rb', line 28 def call(name, define_method: nil, define_predicate: nil, **) argument = Cuprum::Cli::Argument.new(name:, **) defined_arguments << argument define_method = ([:type] != :boolean) if define_method.nil? define_predicate = ([:type] == :boolean) if define_predicate.nil? define_method_for(argument) if define_method define_predicate_for(argument) if define_predicate argument.name end |