Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
sync up console approach with rake approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfine committed Mar 1, 2013
1 parent 0ac5d38 commit 6bdb238
Showing 1 changed file with 4 additions and 49 deletions.
53 changes: 4 additions & 49 deletions lib/heroku/command/run.rb
Expand Up @@ -91,12 +91,11 @@ def rake
# >>
#
def console
puts "`heroku #{current_command}` has been removed. Please use: `heroku run` instead."
puts "For more information, please see:"
puts " * https://devcenter.heroku.com/articles/one-off-dynos"
puts " * https://devcenter.heroku.com/articles/rails3#console"
puts " * https://devcenter.heroku.com/articles/console-bamboo"
deprecate("`heroku #{current_command}` has been deprecated. Please use `heroku run rake` instead.")
command = "console #{args.join(' ')}"
run_attached(command)
end

alias_command "console", "run:console"

protected
Expand Down Expand Up @@ -133,48 +132,4 @@ def rendezvous_session(rendezvous_url, &on_connect)
set_buffer(true)
end
end

def console_history_dir
FileUtils.mkdir_p(path = "#{home_directory}/.heroku/console_history")
path
end

def console_session(app)
heroku.console(app) do |console|
console_history_read(app)

display "Ruby console for #{app}.#{heroku.host}"
while cmd = Readline.readline('>> ')
unless cmd.nil? || cmd.strip.empty?
console_history_add(app, cmd)
break if cmd.downcase.strip == 'exit'
display console.run(cmd)
end
end
end
end

def console_history_file(app)
"#{console_history_dir}/#{app}"
end

def console_history_read(app)
history = File.read(console_history_file(app)).split("\n")
if history.size > 50
history = history[(history.size - 51),(history.size - 1)]
File.open(console_history_file(app), "w") { |f| f.puts history.join("\n") }
end
history.each { |cmd| Readline::HISTORY.push(cmd) }
rescue Errno::ENOENT
rescue Exception => ex
display "Error reading your console history: #{ex.message}"
if confirm("Would you like to clear it? (y/N):")
FileUtils.rm(console_history_file(app)) rescue nil
end
end

def console_history_add(app, cmd)
Readline::HISTORY.push(cmd)
File.open(console_history_file(app), "a") { |f| f.puts cmd + "\n" }
end
end

0 comments on commit 6bdb238

Please sign in to comment.