Skip to content

Commit c3e4575

Browse files
authored
SQL: new SQL CLI logo (#35261)
Added new SQL CLI logo representing the Elastic logo "painted" with "Elastic" words, "SQL" under the logo and version on the last line
1 parent 348c28d commit c3e4575

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

x-pack/plugin/sql/qa/src/main/java/org/elasticsearch/xpack/sql/qa/cli/EmbeddedCli.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.cli.Terminal;
1212
import org.elasticsearch.common.Nullable;
1313
import org.elasticsearch.common.Strings;
14-
1514
import org.elasticsearch.core.internal.io.IOUtils;
1615
import org.elasticsearch.xpack.sql.cli.Cli;
1716
import org.elasticsearch.xpack.sql.cli.CliTerminal;
@@ -151,10 +150,21 @@ protected boolean addShutdownHook() {
151150
assertEquals("", readLine());
152151
}
153152

154-
// Throw out the logo
155-
while (false == readLine().contains("SQL")) {
156-
;
153+
// Read until the first "good" line (skip the logo or read until an exception)
154+
boolean isLogoOrException = false;
155+
while (!isLogoOrException) {
156+
String line = readLine();
157+
if ("SQL".equals(line.trim())) {
158+
// it's almost the bottom of the logo, so read the next line (the version) and break out of the loop
159+
readLine();
160+
isLogoOrException = true;
161+
} else if (line.contains("Exception")) {
162+
// if it's an exception, just break out of the loop and don't read the next line
163+
// as it will swallow the exception and IT tests won't catch it
164+
isLogoOrException = true;
165+
}
157166
}
167+
158168
assertConnectionTest();
159169
} catch (IOException e) {
160170
try {

x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/PrintLogoCommand.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import org.elasticsearch.xpack.sql.cli.Cli;
99
import org.elasticsearch.xpack.sql.cli.CliTerminal;
1010
import org.elasticsearch.xpack.sql.cli.FatalCliException;
11+
import org.elasticsearch.xpack.sql.client.Version;
1112

1213
import java.io.BufferedReader;
1314
import java.io.IOException;
1415
import java.io.InputStream;
1516
import java.io.InputStreamReader;
1617
import java.nio.charset.StandardCharsets;
18+
import java.util.Arrays;
1719
import java.util.regex.Matcher;
1820
import java.util.regex.Pattern;
1921

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

3537
public void printLogo(CliTerminal terminal) {
3638
terminal.clear();
39+
int lineLength = 0;
3740
try (InputStream in = Cli.class.getResourceAsStream("/logo.txt")) {
3841
if (in == null) {
3942
throw new FatalCliException("Could not find logo!");
4043
}
4144
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
4245
String line;
4346
while ((line = reader.readLine()) != null) {
47+
lineLength = Math.max(lineLength, line.length());
4448
terminal.println(line);
4549
}
4650
}
4751
} catch (IOException e) {
4852
throw new FatalCliException("Could not load logo!", e);
4953
}
5054

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
Elasticsearch SQL
1+
asticElasticE
2+
ElasticE sticEla
3+
sticEl ticEl Elast
4+
lasti Elasti tic
5+
cEl ast icE
6+
icE as cEl
7+
icE as cEl
8+
icEla las El
9+
sticElasticElast icElas
10+
las last ticElast
11+
El asti asti stic
12+
El asticEla Elas icE
13+
El Elas cElasticE ticEl cE
14+
Ela ticEl ticElasti cE
15+
las astic last icE
16+
sticElas asti stic
17+
icEl sticElasticElast
18+
icE sticE ticEla
19+
icE sti cEla
20+
icEl sti Ela
21+
cEl sti cEl
22+
Ela astic ticE
23+
asti ElasticElasti
24+
ticElasti lasticElas
25+
ElasticElast
26+
27+
SQL

x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/command/BuiltinCommandTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.elasticsearch.test.ESTestCase;
99
import org.elasticsearch.xpack.sql.cli.TestTerminal;
1010
import org.elasticsearch.xpack.sql.client.HttpClient;
11+
import org.elasticsearch.xpack.sql.client.Version;
1112

1213
import static org.hamcrest.Matchers.containsString;
1314
import static org.mockito.Mockito.mock;
@@ -93,6 +94,7 @@ public void testPrintLogo() throws Exception {
9394
testTerminal.print("not clean");
9495
assertTrue(new PrintLogoCommand().handle(testTerminal, cliSession, "logo"));
9596
assertThat(testTerminal.toString(), containsString("SQL"));
97+
assertThat(testTerminal.toString(), containsString(Version.CURRENT.version));
9698
verifyNoMoreInteractions(httpClient);
9799
}
98100

0 commit comments

Comments
 (0)