Class: Secrets::App::CLI
- Inherits:
-
Object
- Object
- Secrets::App::CLI
- Includes:
- Secrets
- Defined in:
- lib/secrets/app/cli.rb
Constant Summary
Constants included from Secrets
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#key ⇒ Object
Returns the value of attribute key.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#output_proc ⇒ Object
Returns the value of attribute output_proc.
-
#password ⇒ Object
Returns the value of attribute password.
-
#print_proc ⇒ Object
Returns the value of attribute print_proc.
-
#write_proc ⇒ Object
Returns the value of attribute write_proc.
Instance Method Summary collapse
- #command ⇒ Object
- #editor ⇒ Object
- #error(hash) ⇒ Object
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Methods included from Secrets
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/secrets/app/cli.rb', line 29 def initialize(argv) begin self.opts = parse(argv.dup) rescue StandardError => e error exception: e return end configure_color(argv) define_output self.action = { opts[:encrypt] => :encr, opts[:decrypt] => :decr }[true] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
21 22 23 |
# File 'lib/secrets/app/cli.rb', line 21 def action @action end |
#key ⇒ Object
Returns the value of attribute key.
21 22 23 |
# File 'lib/secrets/app/cli.rb', line 21 def key @key end |
#opts ⇒ Object
Returns the value of attribute opts.
21 22 23 |
# File 'lib/secrets/app/cli.rb', line 21 def opts @opts end |
#output_proc ⇒ Object
Returns the value of attribute output_proc.
21 22 23 |
# File 'lib/secrets/app/cli.rb', line 21 def output_proc @output_proc end |
#password ⇒ Object
Returns the value of attribute password.
21 22 23 |
# File 'lib/secrets/app/cli.rb', line 21 def password @password end |
#print_proc ⇒ Object
Returns the value of attribute print_proc.
21 22 23 |
# File 'lib/secrets/app/cli.rb', line 21 def print_proc @print_proc end |
#write_proc ⇒ Object
Returns the value of attribute write_proc.
21 22 23 |
# File 'lib/secrets/app/cli.rb', line 21 def write_proc @write_proc end |
Instance Method Details
#command ⇒ Object
41 42 43 44 |
# File 'lib/secrets/app/cli.rb', line 41 def command @command_class ||= Secrets::App::Commands.find_command_class(opts) @command ||= @command_class.new(self) if @command_class end |
#editor ⇒ Object
86 87 88 |
# File 'lib/secrets/app/cli.rb', line 86 def editor ENV['EDITOR'] || '/bin/vi' end |
#error(hash) ⇒ Object
82 83 84 |
# File 'lib/secrets/app/cli.rb', line 82 def error(hash) Secrets::App.error(hash.merge(config: (opts ? opts.to_hash : {}))) end |
#run ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/secrets/app/cli.rb', line 46 def run return Secrets::App.exit_code if Secrets::App.exit_code != 0 define_private_key decrypt_private_key if should_decrypt_private_key? verify_private_key_encoding if key if command return self.output_proc.call(command.run) else # command was not found. Reset output to printing, and return an error. self.output_proc = print_proc command_not_found_error! end rescue ::OpenSSL::Cipher::CipherError => e error type: 'Cipher Error', details: e., reason: 'Perhaps either the secret is invalid, or encrypted data is corrupt.', exception: e rescue Secrets::Errors::InvalidEncodingPrivateKey => e error type: 'Private Key Error', details: 'Private key does not appear to be properly encoded. ', reason: (opts[:password] ? nil : 'Perhaps the key is password-protected?'), exception: e rescue Secrets::Errors::Error => e error type: 'Error', details: e., exception: e rescue StandardError => e error exception: e end |