Class: Maquina::Credentials::CLI
- Inherits:
-
Object
- Object
- Maquina::Credentials::CLI
- Defined in:
- lib/maquina/credentials/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, stdout:, stderr:, stdin:) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv, stdout:, stderr:, stdin:) ⇒ CLI
Returns a new instance of CLI.
14 15 16 17 18 19 20 |
# File 'lib/maquina/credentials/cli.rb', line 14 def initialize(argv, stdout:, stderr:, stdin:) @argv = argv.dup @stdout = stdout @stderr = stderr @stdin = stdin @credentials_path = nil end |
Class Method Details
.start(argv, stdout: $stdout, stderr: $stderr, stdin: $stdin) ⇒ Object
10 11 12 |
# File 'lib/maquina/credentials/cli.rb', line 10 def self.start(argv, stdout: $stdout, stderr: $stderr, stdin: $stdin) new(argv, stdout: stdout, stderr: stderr, stdin: stdin).run end |
Instance Method Details
#run ⇒ Object
22 23 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/maquina/credentials/cli.rb', line 22 def run command = parser.parse!(@argv).first case command when "help", nil @stdout.puts parser 0 when "generate" generate when "read" read(@argv[1]) when "write" write else @stderr.puts parser command ? 1 : 0 end rescue OptionParser::ParseError => error @stderr.puts error. @stderr.puts parser 1 rescue MasterKeyMissing @stderr.puts "MAQUINA_MASTER_KEY is required" 1 rescue DecryptionFailed @stderr.puts "Failed to decrypt credentials" 1 rescue Psych::Exception @stderr.puts "Input must be a valid YAML hash" 1 end |