Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 4 additions & 49 deletions lib/heroku/command/run.rb
Original file line number Diff line number Diff line change
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 console` 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