Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;

import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.xpack.sql.cli.Cli;
import org.elasticsearch.xpack.sql.cli.CliTerminal;
Expand Down Expand Up @@ -151,10 +150,21 @@ protected boolean addShutdownHook() {
assertEquals("", readLine());
}

// Throw out the logo
while (false == readLine().contains("SQL")) {
;
// Read until the first "good" line (skip the logo or read until an exception)
boolean isLogoOrException = false;
while (!isLogoOrException) {
String line = readLine();
if ("SQL".equals(line.trim())) {
// it's almost the bottom of the logo, so read the next line (the version) and break out of the loop
readLine();
isLogoOrException = true;
} else if (line.contains("Exception")) {
// if it's an exception, just break out of the loop and don't read the next line
// as it will swallow the exception and IT tests won't catch it
isLogoOrException = true;
}
}

assertConnectionTest();
} catch (IOException e) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import org.elasticsearch.xpack.sql.cli.Cli;
import org.elasticsearch.xpack.sql.cli.CliTerminal;
import org.elasticsearch.xpack.sql.cli.FatalCliException;
import org.elasticsearch.xpack.sql.client.Version;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -34,20 +36,26 @@ protected boolean doHandle(CliTerminal terminal, CliSession cliSession, Matcher

public void printLogo(CliTerminal terminal) {
terminal.clear();
int lineLength = 0;
try (InputStream in = Cli.class.getResourceAsStream("/logo.txt")) {
if (in == null) {
throw new FatalCliException("Could not find logo!");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
lineLength = Math.max(lineLength, line.length());
terminal.println(line);
}
}
} catch (IOException e) {
throw new FatalCliException("Could not load logo!", e);
}

// print the version centered on the last line
char[] whitespaces = new char[(lineLength - Version.CURRENT.version.length()) / 2];
Arrays.fill(whitespaces, ' ');
terminal.println(new StringBuilder().append(whitespaces).append(Version.CURRENT.version).toString());
terminal.println();
}

Expand Down
28 changes: 27 additions & 1 deletion x-pack/plugin/sql/sql-cli/src/main/resources/logo.txt
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
Elasticsearch SQL
asticElasticE
ElasticE sticEla
sticEl ticEl Elast
lasti Elasti tic
cEl ast icE
icE as cEl
icE as cEl
icEla las El
sticElasticElast icElas
las last ticElast
El asti asti stic
El asticEla Elas icE
El Elas cElasticE ticEl cE
Ela ticEl ticElasti cE
las astic last icE
sticElas asti stic
icEl sticElasticElast
icE sticE ticEla
icE sti cEla
icEl sti Ela
cEl sti cEl
Ela astic ticE
asti ElasticElasti
ticElasti lasticElas
ElasticElast

SQL
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.sql.cli.TestTerminal;
import org.elasticsearch.xpack.sql.client.HttpClient;
import org.elasticsearch.xpack.sql.client.Version;

import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -93,6 +94,7 @@ public void testPrintLogo() throws Exception {
testTerminal.print("not clean");
assertTrue(new PrintLogoCommand().handle(testTerminal, cliSession, "logo"));
assertThat(testTerminal.toString(), containsString("SQL"));
assertThat(testTerminal.toString(), containsString(Version.CURRENT.version));
verifyNoMoreInteractions(httpClient);
}

Expand Down