Class: Chimps::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/chimps-cli/commands/base.rb

Overview

A base class from which to subclass specific commands. A subclass should

  • define class constants BANNER and HELP which

  • will display the appropriate help to the user.

  • add specific options by defining a method that begins with define and ends with options (i.e. - define_output_options to add options related to output).

  • define a method execute! which will actually run the command.

Constant Summary collapse

USAGE =

Appears when printing help for this command, as the very first line. Should be one-line summary of how to use this command.

"Define #{self}::USAGE when you subclass Chimps::Command"
HELP =

Appears when printing help for this command. Should consist of general help or examples of the command iteslf. Help on specific options is automatically generated.

"Define #{self}::HELP when you subclass Chimps::Command"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Chimps::Command

Create a new command. Will define options specific to subclases, parse the given argv, and load the global Chimps configuration. Will not execute the command.

Parameters:

  • (Configliere::Param)


37
38
39
# File 'lib/chimps-cli/commands/base.rb', line 37

def initialize config
  self.config = config
end

Instance Attribute Details

#configConfigliere::Param

The configuration settings for this command.

Returns:

  • (Configliere::Param)


29
30
31
# File 'lib/chimps-cli/commands/base.rb', line 29

def config
  @config
end

Class Method Details

.nameString

The name of this command, including the Chimps::Commands prefix.

Returns:

  • (String)


45
46
47
# File 'lib/chimps-cli/commands/base.rb', line 45

def self.name
  self.to_s.downcase
end

Instance Method Details

#execute!Object

Run this command.

Will raise a NotImplementedError for Chimps::Command itself – subclasses are expected to redefine this method.

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/chimps-cli/commands/base.rb', line 61

def execute!
  raise NotImplementedError.new("Redefine the `execute!' method in a subclass of #{self.class}.")
end

#nameString

The name of this command, excluding the Chimps::Commands prefix.

Returns:

  • (String)


53
54
55
# File 'lib/chimps-cli/commands/base.rb', line 53

def name
  self.class.name.split('::').last
end