Class: SshTresor::CLI Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Command-line interface for the ssh-tresor executable.

This class is intentionally small and delegates cryptographic operations to Tresor. Library callers should use Vault instead.

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CLI.

Parameters:

  • argv (Array<String>)

    command-line arguments excluding executable name.



17
18
19
# File 'lib/ssh_tresor/cli.rb', line 17

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

Instance Method Details

#runInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Dispatches the requested CLI command.

Returns:

  • (Integer)

    process exit code.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ssh_tresor/cli.rb', line 24

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