Class: SshTresor::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



10
11
12
# File 'lib/ssh_tresor/cli.rb', line 10

def initialize(argv)
  @argv = argv.dup
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ssh_tresor/cli.rb', line 14

def run
  command = @argv.shift
  return help if command.nil? || %w[-h --help help].include?(command)
  return version if %w[-v --version version].include?(command)

  case command
  when "encrypt"
    encrypt_command
  when "decrypt"
    decrypt_command
  when "add-key"
    add_key_command
  when "remove-key"
    remove_key_command
  when "list-slots"
    list_slots_command
  when "list-keys"
    list_keys_command
  else
    warn "Unknown command: #{command}"
    help(1)
  end
rescue Error => e
  warn "Error: #{e.message}"
  e.exit_code
rescue OptionParser::ParseError => e
  warn "Error: #{e.message}"
  Error::EXIT_GENERAL_ERROR
end