Class: Vaulty::CLI::Delete

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#banner, call, #prompt, #table

Constructor Details

#initialize(catacomb:) ⇒ Delete

Returns a new instance of Delete.



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

def initialize(catacomb:)
  @catacomb = catacomb
end

Instance Attribute Details

#catacombObject (readonly)

Returns the value of attribute catacomb.



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

def catacomb
  @catacomb
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vaulty/cli/delete.rb', line 9

def call
  banner("Current value #{catacomb.path.inspect}")
  # Render the tree first so the user knows what we will delete
  vaulty_tree = Vaulty::CLI::Tree.call(catacomb: catacomb)
  # Confirmation
  return if prompt.no?('All above data will be ' \
                        'recursively deleted! Are you sure?', color: :red)

  banner(catacomb.path, color: :red)
  # Start deleting
  delete_recursively(vaulty_tree.children, [catacomb.path])
  # Delete the route of the path
  catacomb.delete
  prompt.ok("Successfully deleted everything in path #{catacomb.path}")
end