Skip to content

Commit

Permalink
SQL: Teach the CLI to ignore empty commands
Browse files Browse the repository at this point in the history
Cause the CLI to ignore commands that are empty or consist only of
newlines. This is a fairly standard thing for SQL CLIs to do.

It looks like:
```
sql> ;
sql>
   |
   | ;
sql> exit;
Bye!
```

I think I *could* have implemented this with a `CliCommand` that throws
out empty string but it felt simpler to bake it in to the `CliRepl`.

Closes elastic#30000
  • Loading branch information
nik9000 committed Apr 30, 2018
1 parent 725a5af commit 9b1575f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public void execute() {
multiLine.setLength(0);
}

// Skip empty commands
if (line.isEmpty()) {
continue;
}

// special case to handle exit
if (isExit(line)) {
cliTerminal.line().em("Bye!").ln();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ public void testBasicCliFunctionality() throws Exception {
verifyNoMoreInteractions(mockCommand, mockSession);
}

/**
* Test that empty commands are skipped. This includes commands that are
* just new lines.
*/
public void testEmptyNotSent() {
CliTerminal cliTerminal = new TestTerminal(
";",
"",
"",
";",
"exit;"
);

CliSession mockSession = mock(CliSession.class);
CliCommand mockCommand = mock(CliCommand.class);

CliRepl cli = new CliRepl(cliTerminal, mockSession, mockCommand);
cli.execute();

verify(mockCommand, times(1)).handle(cliTerminal, mockSession, "logo");
verifyNoMoreInteractions(mockSession, mockCommand);
}

public void testFatalCliExceptionHandling() throws Exception {
CliTerminal cliTerminal = new TestTerminal(
Expand Down

0 comments on commit 9b1575f

Please sign in to comment.