Skip to content

Commit

Permalink
REPL console: throw Exception if redirecting console script output
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Mar 8, 2020
1 parent 6fbdb25 commit b8d7936
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,10 @@ public void trace(final Object object) {
if (object instanceof SystemRegistryImpl.CommandData) {
toPrint = ((SystemRegistryImpl.CommandData)object).rawLine();
}
} else if (level > 1) {
if (object instanceof SystemRegistryImpl.CommandData) {
toPrint = ((SystemRegistryImpl.CommandData)object).toString();
}
}
println(options, toPrint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,12 @@ private List<CommandData> compileCommandLine(String commandLine) {
String rawCommand = parser.getCommand(words.get(first));
String command = ConsoleEngine.plainCommand(rawCommand);
String variable = parser.getVariable(words.get(first));
boolean aliasCommand = false;
if (isCommandAlias(command)) {
ap.parse(parser, replaceCommandAlias(variable, command, nextRawLine));
rawCommand = ap.rawCommand();
command = ap.command();
words = ap.args();
first = 0;
aliasCommand = true;
}
if (((first > 0 && isCommandOrScript(command)) || (first == 0 && scriptStore.isConsoleScript(command)))
&& !rawCommand.startsWith(":") ) {
Expand Down Expand Up @@ -1011,6 +1009,9 @@ public Object execute(String line) throws Exception {
List<CommandData> cmds = compileCommandLine(line);
for (int i = 0; i < cmds.size(); i++) {
CommandData cmd = cmds.get(i);
if (cmd.file() != null && scriptStore.isConsoleScript(cmd.command())) {
throw new IllegalArgumentException("Console script output cannot be redirected!");
}
try {
outputStream.closeAndReset();
if (consoleId != null && !consoleEngine().isExecuting()) {
Expand All @@ -1019,7 +1020,7 @@ public Object execute(String line) throws Exception {
exception = null;
statement = false;
postProcessed = false;
if ((cmd.variable() != null || cmd.file() != null) && !scriptStore.isConsoleScript(cmd.command())) {
if (cmd.variable() != null || cmd.file() != null) {
if (cmd.file() != null) {
outputStream.redirect(cmd.file(), cmd.append());
} else if (consoleId != null) {
Expand Down

0 comments on commit b8d7936

Please sign in to comment.