Skip to content

Commit

Permalink
further cleanup and tweaks on top of latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Apr 5, 2012
1 parent e1f61b2 commit 55cc3ed
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
24 changes: 16 additions & 8 deletions lib/ext/heroku/command/apps.rb
Expand Up @@ -103,9 +103,13 @@ def create
stack = extract_option('--stack', 'aspen-mri-1.8.6') stack = extract_option('--stack', 'aspen-mri-1.8.6')
timeout = extract_option('--timeout', 30).to_i timeout = extract_option('--timeout', 30).to_i
name = args.shift.downcase.strip rescue nil name = args.shift.downcase.strip rescue nil
style_action("creating #{name}") if name
style_action("Creating #{name}")
else
style_action("Creating")
end
info = heroku.create_app(name, {:stack => stack}) info = heroku.create_app(name, {:stack => stack})
name = info["name"] name = info["name"]
begin begin
if info["create_status"] == "creating" if info["create_status"] == "creating"
Timeout::timeout(timeout) do Timeout::timeout(timeout) do
Expand All @@ -117,10 +121,11 @@ def create
end end
end end
hputs("done, stack is #{info["stack"]}") hputs("done, stack is #{info["stack"]}")
hputs


(options[:addons] || "").split(",").each do |addon| (options[:addons] || "").split(",").each do |addon|
addon.strip! addon.strip!
style_action("adding #{addon} to #{name}") style_action("Adding #{addon} to #{name}")
heroku.install_addon(name, addon) heroku.install_addon(name, addon)
hputs("done") hputs("done")
end end
Expand All @@ -130,8 +135,8 @@ def create
end end


style_object({ style_object({
:git_url => info["git_url"], "Git URL" => info["git_url"],
:web_url => info["web_url"] "Web URL" => info["web_url"]
}) })
rescue Timeout::Error rescue Timeout::Error
error("Timed Out! Check heroku status for known issues.") error("Timed Out! Check heroku status for known issues.")
Expand All @@ -150,9 +155,10 @@ def rename
newname = args.shift.downcase.strip rescue '' newname = args.shift.downcase.strip rescue ''
raise(Heroku::Command::CommandFailed, "Must specify a new name.") if newname == '' raise(Heroku::Command::CommandFailed, "Must specify a new name.") if newname == ''


style_action("renaming #{app} to #{newname}") style_action("Renaming #{app} to #{newname}")
heroku.update(app, :name => newname) heroku.update(app, :name => newname)
hputs("done") hputs("done")
hputs


info = heroku.info(newname) info = heroku.info(newname)
style_object({ style_object({
Expand Down Expand Up @@ -182,6 +188,8 @@ def open
info = heroku.info(app) info = heroku.info(app)
url = info[:web_url] url = info[:web_url]
style_action("opening #{url}") style_action("opening #{url}")
hputs("done")
hputs
Launchy.open url Launchy.open url
end end


Expand All @@ -197,12 +205,11 @@ def destroy
raise Heroku::Command::CommandFailed.new("Usage: heroku apps:destroy --app APP") raise Heroku::Command::CommandFailed.new("Usage: heroku apps:destroy --app APP")
end end


action("destroying #{app} (including all add-ons)")

heroku.info(app) # fail fast if no access or doesn't exist heroku.info(app) # fail fast if no access or doesn't exist


message = "WARNING: Potentially Destructive Action\nThis command will destroy #{app} (including all add-ons)." message = "WARNING: Potentially Destructive Action\nThis command will destroy #{app} (including all add-ons)."
if confirm_command(app, message) if confirm_command(app, message)
style_action("destroying #{app} (including all add-ons)")
heroku.destroy(app) heroku.destroy(app)
if remotes = git_remotes(Dir.pwd) if remotes = git_remotes(Dir.pwd)
remotes.each do |remote_name, remote_app| remotes.each do |remote_name, remote_app|
Expand All @@ -211,6 +218,7 @@ def destroy
end end
end end
hputs("done") hputs("done")
hputs
end end
end end


Expand Down
15 changes: 9 additions & 6 deletions lib/ext/heroku/command/ps.rb
Expand Up @@ -93,19 +93,20 @@ def index
def restart def restart
opts = case args.first opts = case args.first
when NilClass then when NilClass then
style_action("Restarting processes") style_action("Restarting Processes")
{} {}
when /.+\..+/ when /.+\..+/
ps = args.first ps = args.first
style_action("Restarting #{ps} process") style_action("Restarting #{ps} Process")
{ :ps => ps } { :ps => ps }
else else
type = args.first type = args.first
style_action("Restarting #{type} processes") style_action("Restarting #{type} Processes")
{ :type => type } { :type => type }
end end
heroku.ps_restart(app, opts) heroku.ps_restart(app, opts)
hputs("done") hputs("done")
hputs
end end


alias_command "restart", "ps:restart" alias_command "restart", "ps:restart"
Expand All @@ -128,10 +129,11 @@ def scale
error "Usage: heroku ps:scale web=2 worker+1" if changes.empty? error "Usage: heroku ps:scale web=2 worker+1" if changes.empty?


changes.each do |process, amount| changes.each do |process, amount|
style_action("scaling #{process} processes") style_action("Scaling #{process} Processes")
amount.gsub!("=", "") amount.gsub!("=", "")
new_qty = heroku.ps_scale(app, :type => process, :qty => amount) new_qty = heroku.ps_scale(app, :type => process, :qty => amount)
hputs("done, now running #{new_qty}") hputs("done, now running #{new_qty}")
hputs
end end
end end


Expand All @@ -147,18 +149,19 @@ def stop
opt = opt =
if (args.first =~ /.+\..+/) if (args.first =~ /.+\..+/)
ps = args.first ps = args.first
style_action("stopping #{ps} process") style_action("Stopping #{ps} Process")
{:ps => ps} {:ps => ps}
elsif args.first elsif args.first
type = args.first type = args.first
style_action("stopping #{type} processes") style_action("Stopping #{type} Processes")
{:type => type} {:type => type}
else else
error "Usage: heroku ps:stop PROCESS" error "Usage: heroku ps:stop PROCESS"
end end


heroku.ps_stop(app, opt) heroku.ps_stop(app, opt)
hputs("done") hputs("done")
hputs
end end


alias_command "stop", "ps:stop" alias_command "stop", "ps:stop"
Expand Down
22 changes: 19 additions & 3 deletions lib/ext/heroku/helpers.rb
Expand Up @@ -2,11 +2,12 @@ module Heroku
module Helpers module Helpers


def style_warning(message) def style_warning(message)
hputs("~~~ #{message}") hputs("~~ #{message}")
end end


def style_action(action) def style_action(action)
hprint("=== #{action}") hputs
hprint("++ #{action}... ")
end end


def style_header(header) def style_header(header)
Expand All @@ -16,7 +17,7 @@ def style_header(header)
end end


def style_info(info) def style_info(info)
hputs("=== #{info}") hputs("-- #{info}")
end end


def style_object(object) def style_object(object)
Expand Down Expand Up @@ -52,5 +53,20 @@ def style_object(object)
end end
end end


# monkey-patches

def create_git_remote(remote, url)
return if git('remote').split("\n").include?(remote)
return unless File.exists?(".git")
git "remote add #{remote} #{url}"
display "Git remote #{remote} added"
hputs
end

def format_with_bang(message)
return '' if message.to_s.strip == ""
"!! " + message.split("\n").join("\n!! ")
end

end end
end end

0 comments on commit 55cc3ed

Please sign in to comment.