Class: Castled::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/castled/cli.rb

Constant Summary collapse

COMMANDS =
%w[init backup restore].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



7
8
9
# File 'lib/castled/cli.rb', line 7

def self.run(argv)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/castled/cli.rb', line 11

def run(argv)
  command = argv.first
  if command.nil? || command == "--help" || command == "-h"
    print_usage
    exit command.nil? ? 1 : 0
  end

  unless COMMANDS.include?(command)
    $stderr.puts "Unknown command: #{command}"
    print_usage
    exit 1
  end

  send(command, argv[1..])
rescue Config::Error, Backup::Error => e
  $stderr.puts "Error: #{e.message}"
  exit 1
end