Class: Vaulty::CLI::Remove

Inherits:
Command
  • Object
show all
Defined in:
lib/vaulty/cli/remove.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#banner, call, #prompt, #table

Constructor Details

#initialize(catacomb:, keys:) ⇒ Remove

Returns a new instance of Remove.



5
6
7
8
# File 'lib/vaulty/cli/remove.rb', line 5

def initialize(catacomb:, keys:)
  @catacomb = catacomb
  @keys = keys
end

Instance Attribute Details

#catacombObject (readonly)

Returns the value of attribute catacomb.



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

def catacomb
  @catacomb
end

#keysObject (readonly)

Returns the value of attribute keys.



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

def keys
  @keys
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vaulty/cli/remove.rb', line 10

def call
  found_keys = Array(catacomb.matching_keys(keys))
  raise Vaulty::MissingKeys.new(catacomb.path, keys) if found_keys.empty?

  banner("Found keys #{found_keys.join(', ')} at #{catacomb.path.inspect}")
  table(catacomb.read, highlight: { matching: found_keys, color: :red })
  return if prompt.no?('All above data will be deleted! Are you sure?', color: :red)

  delete_keys(found_keys)
  prompt.ok("Successfully deleted keys #{found_keys.join(', ')} at #{catacomb.path.inspect}")
end