Module: Golem::Command

Defined in:
lib/golem/command.rb

Overview

Namespace for commands.

Defined Under Namespace

Modules: ManageHooks Classes: Auth, Base, ClearRepositories, CreateRepository, DeleteRepository, Environment, SaveConfig, SetupDb, UpdateHooks, UpdateKeysFile

Constant Summary collapse

COMMANDS =

List of command names as symbols.

[:auth, :clear_repositories, :create_repository, :delete_repository, :environment, :save_config, :setup_db, :update_hooks, :update_keys_file]
ALIASES =

Hash of aliases.

{
	:clear_repositories => ["clear-repositories", "clear-repos", "clear_repos"],
	:create_repository => ["create-repository", "create-repo", "create_repo"],
	:delete_repository => ["delete-repository", "delete-repo", "delete_repo"],
	:environment => ["env"],
	:save_config => ["save-config", "save"],
	:setup_db => ["setup-db", "setup"],
	:update_hooks => ["update-hooks"],
	:update_keys_file => ["update-keys-file", "update-keys", "update_keys"],
}

Class Method Summary collapse

Class Method Details

.find(cmd) ⇒ Class

Find command class by name.

Parameters:

  • cmd (Symbol, String)

    command name to search for.

Returns:

  • (Class)

    command class.

Raises:

  • (NameError)

    if class (constant) not found.



47
48
49
50
51
# File 'lib/golem/command.rb', line 47

def self.find(cmd)
	cmd = ALIASES.find {|key, a| a.include?(cmd.to_s)}.first if ALIASES.any? {|key, aliases| aliases.include?(cmd.to_s)}
	abort "Command not understood." unless COMMANDS.include?(cmd.to_sym)
	const_get cmd.to_s.split("_").collect {|p| p.capitalize}.join.to_sym
end

.run(cmd, opts = {:verbose => true}, *args) ⇒ Object

Run a command.

Parameters:

  • cmd (Symbol, String)

    command name to run,

  • opts (Hash) (defaults to: {:verbose => true})
  • *args

    arguments for the command.



31
32
33
# File 'lib/golem/command.rb', line 31

def self.run(cmd, opts = {:verbose => true}, *args)
	find(cmd).new(opts).run(*args)
end

.usage(cmd) ⇒ String

Get command usage to display in help message.

Parameters:

  • cmd (Symbol, String)

    command name.

Returns:

  • (String)

    usage text or empty string.



38
39
40
41
# File 'lib/golem/command.rb', line 38

def self.usage(cmd)
	cmd = find(cmd)
	cmd.const_defined?(:USAGE) ? cmd::USAGE : ""
end