Skip to content

Instantly share code, notes, and snippets.

@weatheredwatcher
Last active October 4, 2017 18:50
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 weatheredwatcher/8f60fe0396fa2baa728827492c33dc03 to your computer and use it in GitHub Desktop.
Save weatheredwatcher/8f60fe0396fa2baa728827492c33dc03 to your computer and use it in GitHub Desktop.
Quick little Ruby app to remove app from Heroku that are in a list.
file='heroku-apps-delete'
File.readlines(file).each do |app|
app=app.strip
system "heroku apps:delete #{app} --confirm #{app}"
end
@weatheredwatcher
Copy link
Author

So, I've been on Heroku since the service first started. That's a long time! Over the years I have built up a massive amount of little apps that I have played with. I decide that it was time to clean up my account and delete all the applications that I no longer run. I didn't want to have to go in an click on each app, go to the settings pane, hit delete and then type the app name in before finally clicking the final delete button.

Using the cli was not that much easier. heroku apps:delete app-name-1234 and it also requires that I type in the name of the app a second time to confirm the delete. They give an option --confirm app-name-1234 that would straight up delete the application. Having to still type in the name of the app twice per application was not something that I wanted to do. So in the great tradition of hackers every where, I spent one hour figuring out how to do something via a script that actually would have taking me ten minutes to do manually and I will NEVER have to automate this process ever again :). The trick was creating a file with all the apps that I wanted to delete. Loop through it line by line and insert the application name into the command in both arguments.

The problem that I ran into ended up being that readline adds the newline \n on the end of each line, so system was interpreting this as two commands...and it was not working. So I ended up adding the .strip to each app name to remove the new line and then the script worked!!

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