Sha256: 18adf26a95023568e95fcfef742ee1d011f7e0e7b49c460f4600087b18e240a0
Contents?: true
Size: 1.35 KB
Versions: 17
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.warn '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
17 entries across 17 versions & 1 rubygems