Class: SecretKeys::CLI::Read
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#format, #initialize, #secrets
Constructor Details
This class inherits a constructor from SecretKeys::CLI::Base
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
246 247 248 |
# File 'lib/secret_keys/cli.rb', line 246 def key @key end |
Instance Method Details
#action_name ⇒ Object
248 249 250 |
# File 'lib/secret_keys/cli.rb', line 248 def action_name "read" end |
#parse_additional_options(opts) ⇒ Object
252 253 254 255 256 257 258 |
# File 'lib/secret_keys/cli.rb', line 252 def (opts) opts.separator("\n Read options:") @key = nil opts.on("-k", "--key KEY", String, "Key from the file to output. You can use dot notation to read a nested key.") do |value| @key = value end end |
#run! ⇒ Object
260 261 262 263 264 265 266 |
# File 'lib/secret_keys/cli.rb', line 260 def run! raise ArgumentError.new("key is required") if @key.nil? || @key.empty? val = secrets.to_h val = access_key(val, @key) { |parent, key| parent[key] } $stdout.write(val) $stdout.flush end |