Sha256: b2bcf4fbfedee32a9ea763d75c851e48f44fd9abf019cabcd5b243b5cb7b259e

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

desc 'delete-dumps [DIRECTORY]', 'Delete database dump files (*.dump)'
long_desc <<-LONGDESC
Example: `geordi delete-dumps` or `geordi delete-dumps ~/tmp/dumps`

Recursively searches for files ending in `.dump` and offers to delete them. When
no argument is given, two default directories are searched for dump files: the
current working directory and `~/dumps` (for dumps created with geordi).

Will ask for confirmation before actually deleting files.
LONGDESC

def delete_dumps(*locations)
  Interaction.announce 'Retrieving dump files'

  dump_files = []
  if locations.empty?
    locations = [ File.join(Dir.home, 'dumps'), Dir.pwd ]
  end
  locations.map! &File.method(:expand_path)

  Interaction.note "Looking in #{locations.join(', ')}"
  locations.each do |dir|
    directory = File.expand_path(dir)
    unless File.directory? File.realdirpath(directory)
      Interaction.warn "Directory #{directory} does not exist. Skipping."
      next
    end
    dump_files.concat Dir.glob("#{directory}/**/*.dump")
  end
  deletable_dumps = dump_files.flatten.uniq.sort.select &File.method(:file?)

  if deletable_dumps.empty?
    Interaction.note 'No dump files found'
  else
    puts deletable_dumps
    Interaction.prompt('Delete these files?', 'n', /y|yes/) || Interaction.fail('Cancelled.')

    deletable_dumps.each &File.method(:delete)
    Interaction.success 'Done.'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geordi-5.4.0 lib/geordi/commands/delete_dumps.rb
geordi-5.3.0 lib/geordi/commands/delete_dumps.rb
geordi-5.2.4 lib/geordi/commands/delete_dumps.rb