Skip to content

Instantly share code, notes, and snippets.

@cybertk
Created July 25, 2014 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybertk/69fa113254488263a12d to your computer and use it in GitHub Desktop.
Save cybertk/69fa113254488263a12d to your computer and use it in GitHub Desktop.
Remove multiple apps against regex pattern
#!/usr/bin/ruby
require 'optparse'
def RemoveHerokuAppsWithPattern(pattern, confirm)
apps = []
# Find apps to remove
`heroku apps`.lines do |line|
_, app = line.match(/(#{pattern}.*)/).to_a
apps << app unless not app
end
if not confirm
puts "The following apps will be removed \n#{apps.join("\n")}"
exit
end
apps.each do |app|
`heroku destroy -a #{app} --confirm #{app}`
puts "#{app} removed"
end
end
options = {}
optparse = OptionParser.new do |opts|
options[:pattern] = ''
opts.on( '-p', '--pattern PATTERN', 'App match aginst the PATTERN' ) do |pattern|
options[:pattern] = pattern
end
options[:confirm] = false
opts.on('--confirm', 'Confirm delete' ) do
options[:confirm] = true
end
end
optparse.parse!
RemoveHerokuAppsWithPattern(options[:pattern], options[:confirm])
@cybertk
Copy link
Author

cybertk commented Jul 25, 2014

$ ./heroku_remove_apps.rb -p 'api-release-0-1-'
$ ./heroku_remove_apps.rb -p 'api-release-0-1-' --confirm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment