Module: Blockspring::CLI::Command

Defined in:
lib/blockspring/cli/command.rb

Defined Under Namespace

Classes: Auth, Base, Block, Help, Run, Version

Class Method Summary collapse

Class Method Details

.command_aliasesObject



9
10
11
# File 'lib/blockspring/cli/command.rb', line 9

def self.command_aliases
  @@command_aliases ||= {}
end

.commandsObject



5
6
7
# File 'lib/blockspring/cli/command.rb', line 5

def self.commands
  @@commands ||= {}
end

.filesObject



13
14
15
# File 'lib/blockspring/cli/command.rb', line 13

def self.files
  @@files ||= Hash.new {|hash,key| hash[key] = File.readlines(key).map {|line| line.strip}}
end

.loadObject



17
18
19
20
21
# File 'lib/blockspring/cli/command.rb', line 17

def self.load
  Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
    require file
  end
end

.namespacesObject



42
43
44
# File 'lib/blockspring/cli/command.rb', line 42

def self.namespaces
  @@namespaces ||= {}
end

.parse(cmd) ⇒ Object



38
39
40
# File 'lib/blockspring/cli/command.rb', line 38

def self.parse(cmd)
  commands[cmd] || commands[command_aliases[cmd]]
end

.register_command(command) ⇒ Object



23
24
25
# File 'lib/blockspring/cli/command.rb', line 23

def self.register_command(command)
  commands[command[:command]] = command
end

.register_namespace(namespace) ⇒ Object



46
47
48
# File 'lib/blockspring/cli/command.rb', line 46

def self.register_namespace(namespace)
  namespaces[namespace[:name]] = namespace
end

.run(cmd, arguments = []) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/blockspring/cli/command.rb', line 27

def self.run(cmd, arguments=[])
  command = parse(cmd)
  if command
    command_instance = command[:klass].new(arguments.dup)
    command_instance.send(command[:method])
  else
    puts "#{cmd} is not a command."
    puts "See `blockspring help` for a list of commands."
  end
end