class Arcanus::Command::Base
Abstract base class of all commands.
@abstract
Attributes
arguments[R]
@return [Array<String>]
ui[R]
@return [Arcanus::UI]
Public Class Methods
description(desc = nil)
click to toggle source
# File lib/arcanus/command/base.rb, line 28 def description(desc = nil) @description = desc if desc @description end
from_arguments(ui, arguments)
click to toggle source
Create a command from a list of arguments.
@param ui [Arcanus::UI] @param arguments [Array<String>] @return [Arcanus::Command::Base] appropriate command for the given
arguments
# File lib/arcanus/command/base.rb, line 15 def from_arguments(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(ui, arguments) end
new(ui, arguments)
click to toggle source
@param ui [Arcanus::UI] @param arguments [Array<String>]
# File lib/arcanus/command/base.rb, line 40 def initialize(ui, arguments) @ui = ui @arguments = arguments end
short_name()
click to toggle source
# File lib/arcanus/command/base.rb, line 33 def short_name name.split('::').last.downcase end
Public Instance Methods
execute()
click to toggle source
Executes the command given the previously-parsed arguments.
# File lib/arcanus/command/base.rb, line 53 def execute raise NotImplementedError, 'Define `execute` in Command subclass' end
execute_command(command_arguments)
click to toggle source
Executes another command from the same context as this command.
@param command_arguments [Array<String>]
# File lib/arcanus/command/base.rb, line 60 def execute_command(command_arguments) self.class.from_arguments(ui, command_arguments).execute end
run()
click to toggle source
Parses arguments and executes the command.
# File lib/arcanus/command/base.rb, line 46 def run # TODO: include a parse step here and remove duplicate parsing code from # individual commands execute end
Private Instance Methods
repo()
click to toggle source
Returns information about this repository.
@return [Arcanus::Repo]
# File lib/arcanus/command/base.rb, line 75 def repo @repo ||= Arcanus::Repo.new end