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

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

+ (Class) find(cmd)

Find command class by name.

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

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

Run a 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

+ (String) usage(cmd)

Get command usage to display in help message.



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