Skip to content
This repository has been archived by the owner on Sep 3, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Mar 3, 2013
0 parents commit 8aa6400
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) Tim Pope

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions README.markdown
@@ -0,0 +1,25 @@
# Heroku wildcards

Run a command across multiple apps by including `*` in the app name.

$ heroku ps --app=myapp-*
# myapp-staging
=== web: `bundle exec rails server thin -p $PORT`
web.1: up 2013/03/02 19:40:05 (~ 1h ago)

# myapp-production
=== web: `bundle exec rails server thin -p $PORT`
web.1: up 2013/03/02 11:53:30 (~ 9h ago)
web.2: up 2013/03/02 11:56:05 (~ 9h ago)

You can also match against the Git remote name:

$ heroku info -r*

## Installation

heroku plugins:install https://github.com/tpope/heroku-wildcards.git

## License

Copyright © Tim Pope. MIT License. See LICENSE for details.
65 changes: 65 additions & 0 deletions init.rb
@@ -0,0 +1,65 @@
require 'heroku/command'

class << Heroku::Command

alias boring_old_wildcard_free_run run
def run(cmd, original_args=[])
option = '--app'
pattern = ENV['HEROKU_APP']
args = original_args.dup
args.each_with_index do |arg, i|
case arg
when '--'
break
when /^-(?:a|-app=)(.*)$/
pattern = $1
args.delete_at(i)
break
when /^-(?:a|-app)$/
pattern = args.delete_at(i+1)
args.delete_at(i)
break
when /^-(?:r|-remote=)(.*)$/
pattern = $1
args.delete_at(i)
option = '--remote'
break
when /^-(?:r|-remote)$/
pattern = args.delete_at(i+1)
args.delete_at(i)
option = '--remote'
break
end
end

if !pattern
option = '--remote'
pattern = git("config heroku.remote")[/.+/]
end

if pattern.to_s.include?('*')
found = false
if option == '--remote'
Heroku::Command::Base.allocate.send(:git_remotes).to_a
else
Heroku::Auth.api.get_apps.body.map { |a| [a['name'], a['name']] }
end.each do |candidate, app|
if File.fnmatch?(pattern, candidate)
found = true
if $stdout.tty? && ENV['TERM'] != 'dumb'
display("\e[01m# #{app}\e[00m")
else
display("# #{app}")
end
system($0, cmd, option, candidate, *args)
end
end
unless found
error("You do not have access to any apps matching #{pattern}.")
end
else
boring_old_wildcard_free_run(cmd, original_args)
end
end

end

0 comments on commit 8aa6400

Please sign in to comment.