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

interactively execute multiple commands #905

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions lib/heroku/command/shell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require "heroku/command/base"

# interactive shell for sequential commands
#
class Heroku::Command::Shell < Heroku::Command::Base

# shell
#
# Read multiple commands
#
def index
validate_arguments!

begin
app_or_nil = app
rescue Heroku::Command::CommandFailed
app_or_nil = nil
end
@cmd_tag = app_or_nil ? " (#{app_or_nil})" : ""

require "readline"
require "shellwords"

sorted_commands = (Heroku::Command.commands.keys + Heroku::Command.command_aliases.keys).sort
Readline.completion_append_character = " "
Readline.completion_proc = proc { |s| sorted_commands.grep(/^#{Regexp.escape(s)}/) }

while line = readline
args = line.shellsplit
next if args.empty?
command = args.shift.strip
return if command == "exit"
args.unshift("--app", app_or_nil) if app_or_nil
begin
Heroku::Command.run(command, args)
rescue SystemExit
end
end
puts
end

private

def readline
begin
return Readline.readline("heroku#{@cmd_tag}> ", true)
rescue Interrupt
puts
retry
end
end

end