Class: Cuprum::Cli::Command
- Inherits:
-
Cuprum::Command
- Object
- Cuprum::Command
- Cuprum::Cli::Command
- Extended by:
- Arguments::ClassMethods, Options::ClassMethods
- Includes:
- Metadata, Plumbum::Consumer, Plumbum::Parameters
- Defined in:
- lib/cuprum/cli/command.rb
Overview
Abstract base class for defining CLI commands.
Direct Known Subclasses
Cuprum::Cli::Commands::Ci::RSpecCommand, Cuprum::Cli::Commands::Ci::RSpecEachCommand, Cuprum::Cli::Commands::EchoCommand, Cuprum::Cli::Commands::File::NewCommand
Constant Summary
Constants included from Metadata
Class Method Summary collapse
-
.argument(name, default: nil, description: nil, required: false, type: :string, variadic: false, **options) ⇒ Object
Defines an argument for the command class.
- .dependency(dependency_name) ⇒ Object
- .option(option_name) ⇒ Object
Instance Method Summary collapse
- #call(resolved_arguments: nil, resolved_options: nil) ⇒ Object
-
#initialize ⇒ Command
constructor
A new instance of Command.
Methods included from Arguments::ClassMethods
argument, argument_value, argument_values, resolve_arguments
Methods included from Options::ClassMethods
option, option_value, option_values, resolve_options
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
47 48 49 50 51 52 |
# File 'lib/cuprum/cli/command.rb', line 47 def initialize(**) super() @arguments = {} @options = {} end |
Class Method Details
.argument(name, default: nil, description: nil, required: false, type: :string, variadic: false, **options) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/cuprum/cli/command.rb', line 23 def argument(argument_name, **) return super unless abstract? raise Cuprum::Cli::Metadata::AbstractCommandError, ("define argument :#{argument_name}") end |
.dependency(dependency_name) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/cuprum/cli/command.rb', line 31 def dependency(dependency_name, **) return super unless abstract? raise Cuprum::Cli::Metadata::AbstractCommandError, ("add dependency :#{dependency_name}") end |
.option(option_name) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/cuprum/cli/command.rb', line 39 def option(option_name, **) return super unless abstract? raise Cuprum::Cli::Metadata::AbstractCommandError, ("define option :#{option_name}") end |
Instance Method Details
#call(*arguments, **options) ⇒ Cuprum::Result #call(resolved_arguments:, resolved_options:) ⇒ Cuprum::Result
83 84 85 86 87 88 89 90 |
# File 'lib/cuprum/cli/command.rb', line 83 def call(*, resolved_arguments: nil, resolved_options: nil, **) @arguments = resolved_arguments || self.class.resolve_arguments(*) @options = || self.class.(**) super() end |