Class: FuturoCube::ResourceTool

Inherits:
Object
  • Object
show all
Defined in:
lib/futurocube/resource_tool.rb

Constant Summary collapse

COMMANDS =
{
  'list' => ListCommand.new,
  'verify' => VerifyCommand.new,
  'dump' => DumpCommand.new
}

Instance Method Summary collapse

Instance Method Details

#main(args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/futurocube/resource_tool.rb', line 22

def main(args)
  usage if args.length < 1
  usage(0) if args[0] == '--help'

  command = COMMANDS[args[0]]
  usage if !command

  command_args = args.slice(1..-1)
  usage if !command.args_valid?(command_args)
  begin
    command.exec(*command_args)
  rescue Interrupt => e
    $stderr.puts("Interrupted")
  end
end

#usage(exit_code = 1) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/futurocube/resource_tool.rb', line 14

def usage(exit_code = 1)
  $stderr.puts("Usage:")
  COMMANDS.each_pair do |name, command|
    $stderr.puts("  #{$0} #{name} #{command.usage}")
  end
  exit exit_code
end