Class: Vaulty::CLI::Add

Inherits:
Command show all
Defined in:
lib/vaulty/cli/add.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#banner, call, #prompt, #table

Constructor Details

#initialize(catacomb:, data: {}, files: {}) ⇒ Add

Returns a new instance of Add.

Parameters:

  • catacomb (Catacomb)

    instance

  • data (Hash) (defaults to: {})
  • files (Hash) (defaults to: {})


8
9
10
11
12
# File 'lib/vaulty/cli/add.rb', line 8

def initialize(catacomb:, data: {}, files: {})
  @catacomb = catacomb
  files_with_content = read_file_contents!(files)
  @data = data.merge(files_with_content)
end

Instance Attribute Details

#catacombObject (readonly)

Returns the value of attribute catacomb.



4
5
6
# File 'lib/vaulty/cli/add.rb', line 4

def catacomb
  @catacomb
end

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/vaulty/cli/add.rb', line 4

def data
  @data
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vaulty/cli/add.rb', line 14

def call
  banner("Current value #{catacomb.path.inspect}")
  # Print out the current state
  table(catacomb.read, highlight: { matching: matching_keys, color: :red })
  # If we have matching keys and we don't want to continue, we exit
  return if matching_keys.any? && prompt.no?('Existing secret found, overwrite?')

  # Print we are writing and merge the content
  banner("Writing data to #{catacomb.path.inspect}", color: :red)
  catacomb.merge(data)
  # Print the final state in a table highlight the values we added
  table(catacomb.read, highlight: { matching: data.values, color: :green })
end