Class: Chimps::Command
- Inherits:
-
Object
- Object
- Chimps::Command
- 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
andHELP
which -
will display the appropriate help to the user.
-
add specific options by defining a method that begins with
define
and ends withoptions
(i.e. -define_output_options
to add options related to output). -
define a method
execute!
which will actually run the command.
Direct Known Subclasses
Chimps::Commands::Create, Chimps::Commands::Delete, Chimps::Commands::Destroy, Chimps::Commands::Download, Chimps::Commands::Get, Chimps::Commands::Help, Chimps::Commands::List, Chimps::Commands::Me, Chimps::Commands::Post, Chimps::Commands::Put, Chimps::Commands::Query, Chimps::Commands::Search, Chimps::Commands::Show, Chimps::Commands::Test, Chimps::Commands::Update, Chimps::Commands::Upload
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
-
#config ⇒ Configliere::Param
The configuration settings for this command.
Class Method Summary collapse
-
.name ⇒ String
The name of this command, including the
Chimps::Commands
prefix.
Instance Method Summary collapse
-
#execute! ⇒ Object
Run this command.
-
#initialize(config) ⇒ Chimps::Command
constructor
Create a new command.
-
#name ⇒ String
The name of this command, excluding the
Chimps::Commands
prefix.
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.
37 38 39 |
# File 'lib/chimps-cli/commands/base.rb', line 37 def initialize config self.config = config end |
Instance Attribute Details
#config ⇒ Configliere::Param
The configuration settings for this command.
29 30 31 |
# File 'lib/chimps-cli/commands/base.rb', line 29 def config @config end |
Class Method Details
.name ⇒ String
The name of this command, including the Chimps::Commands
prefix.
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.
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 |
#name ⇒ String
The name of this command, excluding the Chimps::Commands
prefix.
53 54 55 |
# File 'lib/chimps-cli/commands/base.rb', line 53 def name self.class.name.split('::').last end |