Class: SecretKeys::CLI::Base

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

Direct Known Subclasses

Decrypt, Encrypt, Init, Read

Constant Summary collapse

MAX_SUMMARY_LENGTH =
80

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
19
# File 'lib/secret_keys/cli.rb', line 14

def initialize(argv)
  # make sure we can only use stdin once
  @stdin_used = false
  @secrets = nil
  parse_options(argv)
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



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

def secret_key
  @secret_key
end

Instance Method Details

#action_nameObject

Subclasses should return the action name for the help banner



31
32
33
# File 'lib/secret_keys/cli.rb', line 31

def action_name
  "<encrypt|decrypt|read|edit>"
end

#formatObject

Return the output format.



41
42
43
44
# File 'lib/secret_keys/cli.rb', line 41

def format
  return @format if [:json, :yaml].include?(@format)
  secrets.input_format
end

#parse_additional_options(opts) ⇒ Object

Subclasses can override this method to parse additional options beyond the standard set.



22
23
# File 'lib/secret_keys/cli.rb', line 22

def parse_additional_options(opts)
end

#run!Object

Subclasses must implement this method to execute the logic.

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/secret_keys/cli.rb', line 36

def run!
  raise NotImplementedError
end

#secretsSecretKeys

Returns the secrets.

Returns:



26
27
28
# File 'lib/secret_keys/cli.rb', line 26

def secrets
  @secrets ||= SecretKeys.new(@input, @secret_key)
end