Created
July 25, 2014 09:52
-
-
Save cybertk/69fa113254488263a12d to your computer and use it in GitHub Desktop.
Remove multiple apps against regex pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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]) |
Author
cybertk
commented
Jul 25, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment