Master the Heroku CLI from Ruby.
Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
assets added a fun logo Feb 1, 2013
examples
lib
spec
.gitignore
.rspec
.travis.yml
CHANGELOG.md
Gemfile
LICENSE.md
README.md
Rakefile
heroku-commander.gemspec

README.md

Heroku::Commander

Gem Version Build Status Dependency Status Code Climate

Master the Heroku CLI from Ruby.

Usage

Add heroku and heroku-commander to Gemfile.

gem "heroku"
gem "heroku-commander"

Heroku Configuration

Returns a hash of an application's configuration (output from heroku config).

commander = Heroku::Commander.new({ :app => "heroku-commander" })
commander.config # => a hash of all settings for the heroku-commander app

Heroku Processes

Returns or yields an array of processes by running heroku ps.

commander = Heroku::Commander.new({ :app => "heroku-commander" })
commander.processes do |process|
  # try process.pid and process.status
end

Heroku Run

Executes a command via heroku run, pipes and returns output lines. Unlike the heroku client, this also checks the process return code and raises a Heroku::Commander::Errors::CommandError if the latter is not zero, which makes this suitable for Rake tasks.

commander = Heroku::Commander.new({ :app => "heroku-commander" })
commander.run "uname -a" # => [ "Linux 2.6.32-348-ec2 #54-Ubuntu SMP x86_64 GNU" ]

You can specify the dyno size with size.

commander.run "uname -a", { size: "2X" }

Heroku Detached Run

Executes a command via heroku run:detached, spawns a heroku logs --tail -p pid for the process started on Heroku, pipes and returns output lines. This also checks the process return code and raises a Heroku::Commander::Errors::CommandError if the latter is not zero.

commander = Heroku::Commander.new({ :app => "heroku-commander" })
commander.run("uname -a", { :detached => true }) # => [ "Linux 2.6.32-348-ec2 #54-Ubuntu SMP x86_64 GNU" ]

You can examine the output from heroku logs --tail -p pid line-by-line.

commander.run("ls -R", { :detached => true }) do |line|
  # each line from the output of the command
end

You can pass the following options along with :detached:

  • size: dyno size, eg. 2X for double-dynos.
  • tail_timeout: number of seconds to wait before terminating heroku logs --tail, expecting more output (defaults to 5).
  • tail_retries: number of times to restart the tail process on error (defaults to 3).

For more information about Heroku one-off dynos see this documentation.

More Examples

See examples for more.

Contributing

Fork the project. Make your feature addition or bug fix with tests. Send a pull request. Bonus points for topic branches.

Copyright and License

MIT License, see LICENSE for details.

(c) 2013 Daniel Doubrovkine, Frank Macreery, Artsy Inc.