Class: SecretKeys::CLI::Read

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

Constant Summary

Constants inherited from Base

Base::MAX_SUMMARY_LENGTH

Instance Attribute Summary collapse

Attributes inherited from Base

#input, #secret_key

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

#keyObject (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_nameObject



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 parse_additional_options(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

Raises:

  • (ArgumentError)


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