Class: Arcanus::Command::Base Abstract
- Inherits:
-
Object
- Object
- Arcanus::Command::Base
- Includes:
- Utils
- Defined in:
- lib/arcanus/command/base.rb
Overview
This class is abstract.
Abstract base class of all commands.
Class Method Summary collapse
- .description(desc = nil) ⇒ Object
-
.from_arguments(config, ui, arguments) ⇒ Arcanus::Command::Base
Create a command from a list of arguments.
- .short_name ⇒ Object
Instance Method Summary collapse
-
#execute ⇒ Object
Executes the command given the previously-parsed arguments.
-
#execute_command(command_arguments) ⇒ Object
Executes another command from the same context as this command.
-
#initialize(config, ui, arguments) ⇒ Base
constructor
A new instance of Base.
-
#run ⇒ Object
Parses arguments and executes the command.
Methods included from Utils
camel_case, deep_dup, snake_case
Constructor Details
#initialize(config, ui, arguments) ⇒ Base
Returns a new instance of Base.
42 43 44 45 46 |
# File 'lib/arcanus/command/base.rb', line 42 def initialize(config, ui, arguments) @config = config @ui = ui @arguments = arguments end |
Class Method Details
.description(desc = nil) ⇒ Object
29 30 31 32 |
# File 'lib/arcanus/command/base.rb', line 29 def description(desc = nil) @description = desc if desc @description end |
.from_arguments(config, ui, arguments) ⇒ Arcanus::Command::Base
Create a command from a list of arguments.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/arcanus/command/base.rb', line 16 def from_arguments(config, ui, arguments) cmd = arguments.first begin require "arcanus/command/#{Arcanus::Utils.snake_case(cmd)}" rescue LoadError raise Arcanus::Errors::CommandInvalidError, "`arcanus #{cmd}` is not a valid command" end Arcanus::Command.const_get(Arcanus::Utils.camel_case(cmd)).new(config, ui, arguments) end |
.short_name ⇒ Object
34 35 36 |
# File 'lib/arcanus/command/base.rb', line 34 def short_name name.split('::').last.downcase end |
Instance Method Details
#execute ⇒ Object
Executes the command given the previously-parsed arguments.
56 57 58 |
# File 'lib/arcanus/command/base.rb', line 56 def execute raise NotImplementedError, 'Define `execute` in Command subclass' end |
#execute_command(command_arguments) ⇒ Object
Executes another command from the same context as this command.
63 64 65 |
# File 'lib/arcanus/command/base.rb', line 63 def execute_command(command_arguments) self.class.from_arguments(config, ui, command_arguments).execute end |
#run ⇒ Object
Parses arguments and executes the command.
49 50 51 52 53 |
# File 'lib/arcanus/command/base.rb', line 49 def run # TODO: include a parse step here and remove duplicate parsing code from # individual commands execute end |