Module: Cloudkick::Command

Defined in:
lib/cloudkick/command.rb,
lib/cloudkick/commands/base.rb,
lib/cloudkick/commands/help.rb,
lib/cloudkick/commands/version.rb,
lib/cloudkick/commands/parallel.rb

Defined Under Namespace

Classes: Base, CommandFailed, Help, InvalidCommand, Pscp, Pssh, Version

Class Method Summary collapse

Class Method Details

.error(msg) ⇒ Object



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

def error(msg)
  STDERR.puts(msg)
  exit 1
end

.parse(command) ⇒ Object



35
36
37
# File 'lib/cloudkick/command.rb', line 35

def parse(command)
  return eval("Cloudkick::Command::#{command.capitalize}"), :index
end

.run(command, args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cloudkick/command.rb', line 11

def run(command, args)
  begin
    run_internal(command, args.dup)
  rescue InvalidCommand
    error "Unknown command. Run 'cloudkick help' for usage information."
  rescue CommandFailed => e
    error e.message
  rescue Interrupt => e
    error "\n[canceled]"
  end
end

.run_internal(command, args) ⇒ Object

Raises:



23
24
25
26
27
28
# File 'lib/cloudkick/command.rb', line 23

def run_internal(command, args)
  klass, method = parse(command)
  runner = klass.new(args)
  raise InvalidCommand unless runner.respond_to?(method)
  runner.send(method)
end