Permalink
Browse files

Pass the --app option through to the heroku CLI.

This allows people who are deploying to multiple apps to run the generator.
  • Loading branch information...
1 parent 7253eac commit c10b012cfe4cfe2ae2fa34bdc2759fd5a7db4eaf Gabe Berke-Williams committed May 27, 2011
View
@@ -143,6 +143,21 @@ Feature: Install the Gem in a Rails application
config.api_key = ENV['HOPTOAD_API_KEY']
"""
+ Scenario: Support the --app option for the Heroku addon in the generator
+ When I generate a new Rails application
+ And I configure the Hoptoad shim
+ And I configure the Heroku rake shim
+ And I configure the Heroku gem shim with "myapikey" and multiple app support
+ And I configure my application to require the "hoptoad_notifier" gem
+ And I run the hoptoad generator with "--heroku -a myapp"
+ Then the command should have run successfully
+ And I should receive a Hoptoad notification
+ And I should see the Rails version
+ And my Hoptoad configuration should contain the following line:
+ """
+ config.api_key = ENV['HOPTOAD_API_KEY']
+ """
+
Scenario: Filtering parameters in a controller
When I generate a new Rails application
And I configure the Hoptoad shim
@@ -302,15 +302,30 @@ def rails_non_initializer_hoptoad_config_file
@terminal.invoke_heroku_rake_tasks_locally = true
end
-When /^I configure the Heroku gem shim with "([^\"]*)"$/ do |api_key|
+When /^I configure the Heroku gem shim with "([^\"]*)"( and multiple app support)?$/ do |api_key, multi_app|
heroku_script_bin = File.join(TEMP_DIR, "bin")
FileUtils.mkdir_p(heroku_script_bin)
heroku_script = File.join(heroku_script_bin, "heroku")
+ single_app_script = <<-SINGLE
+ #!/bin/bash
+ if [[ $1 == 'console' && $2 == 'puts ENV[%{HOPTOAD_API_KEY}]' ]]; then
+ echo #{api_key}
+ fi
+ SINGLE
+
+ multi_app_script = <<-MULTI
@jyurek

jyurek Jun 2, 2011

Member

Would it be better to have a script that detects the --app option rather than hardcoding it this way?

+ #!/bin/bash
+ if [[ $1 == 'console' && $2 == '--app' && $4 == 'puts ENV[%{HOPTOAD_API_KEY}]' ]]; then
+ echo #{api_key}
+ fi
+ MULTI
+
File.open(heroku_script, "w") do |f|
- f.puts "#!/bin/bash"
- f.puts "if [[ $1 == 'console' && $2 == 'puts ENV[%{HOPTOAD_API_KEY}]' ]]; then"
- f.puts " echo #{api_key}"
- f.puts "fi"
+ if multi_app
+ f.puts multi_app_script
+ else
+ f.puts single_app_script
+ end
end
FileUtils.chmod(0755, heroku_script)
@terminal.prepend_path(heroku_script_bin)
@@ -3,8 +3,9 @@
class HoptoadGenerator < Rails::Generator::Base
def add_options!(opt)
- opt.on('-k', '--api-key=key', String, "Your Hoptoad API key") {|v| options[:api_key] = v}
- opt.on('-h', '--heroku', "Use the Heroku addon to provide your Hoptoad API key") {|v| options[:heroku] = v}
+ opt.on('-k', '--api-key=key', String, "Your Hoptoad API key") { |v| options[:api_key] = v}
+ opt.on('-h', '--heroku', "Use the Heroku addon to provide your Hoptoad API key") { |v| options[:heroku] = v}
+ opt.on('-a', '--app=myapp', String, "Your Heroku app name (only required if deploying to >1 Heroku app)") { |v| options[:app] = v}
end
def manifest
@@ -60,7 +61,8 @@ def determine_api_key
end
def heroku_api_key
- `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
+ app = options[:app] ? " --app #{options[:app]}" : ''
+ `heroku console#{app} 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
end
def heroku?
@@ -4,6 +4,7 @@ class HoptoadGenerator < Rails::Generators::Base
class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Hoptoad API key"
class_option :heroku, :type => :boolean, :desc => "Use the Heroku addon to provide your Hoptoad API key"
+ class_option :app, :aliases => "-a", :type => :string, :desc => "Your Heroku app name (only required if deploying to >1 Heroku app)"
def self.source_root
@_hoptoad_source_root ||= File.expand_path("../../../../../generators/hoptoad/templates", __FILE__)
@@ -71,7 +72,8 @@ def determine_api_key
end
def heroku_api_key
- `heroku console 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
+ app = options[:app] ? " --app #{options[:app]}" : ''
+ `heroku console#{app} 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
end
def heroku?

0 comments on commit c10b012

Please sign in to comment.