Module: Chimps::Commands

Included in:
Chimps::CLI::Runner
Defined in:
lib/chimps/commands.rb,
lib/chimps/commands/help.rb,
lib/chimps/commands/list.rb,
lib/chimps/commands/show.rb,
lib/chimps/commands/test.rb,
lib/chimps/commands/batch.rb,
lib/chimps/commands/query.rb,
lib/chimps/commands/create.rb,
lib/chimps/commands/search.rb,
lib/chimps/commands/update.rb,
lib/chimps/commands/upload.rb,
lib/chimps/commands/destroy.rb,
lib/chimps/commands/download.rb

Overview

A namespace to hold the various commands Chimps defines.

Defined Under Namespace

Classes: Batch, Create, Destroy, Download, Help, List, Query, Search, Show, Test, Update, Upload

Constant Summary collapse

NAMES =

A list of all the commmand names defined by Chimps. Each name maps to a corresponding subclass of Chimps::Command living in the Chimps::Commands module.

%w[search help test create show update destroy upload list download batch query]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.construct(command_name, argv) ⇒ Chimps::Command

Construct a new command from the given command_name and +argv. The resulting command will be initialized but will not have been executed.

Parameters:

Returns:

Raises:



13
14
15
16
17
18
# File 'lib/chimps/commands.rb', line 13

def self.construct command_name, argv
  self.constants.each do |constant_name|
    return "Chimps::Commands::#{constant_name}".constantize.new(argv) if constant_name.downcase == command_name
  end
  raise CLIError.new("Invalid command: #{command_name}.  Try running `chimps help'")
end

Instance Method Details

#command_name?(name) ⇒ true, false

Is name a Chimps command name?

Parameters:

Returns:

  • (true, false)


42
43
44
# File 'lib/chimps/commands.rb', line 42

def command_name? name
  NAMES.include?(name)
end

#construct(command_name, argv) ⇒ Object

Construct a new command from the given command_name and argv.

Delegates to Chimps::Commands.construct, so see its documentation for more information.



25
26
27
# File 'lib/chimps/commands.rb', line 25

def construct command_name, argv
  Chimps::Commands.construct command_name, argv
end