Fix some forbiddens in cli
Original commit: elastic/x-pack-elasticsearch@3dc96c7279
This commit is contained in:
parent
bc2f0fe7ff
commit
d25c23c3b4
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.sql.cli;
|
||||
|
||||
import org.elasticsearch.xpack.sql.cli.net.client.CliHttpClient;
|
||||
import org.elasticsearch.xpack.sql.net.client.SuppressForbidden;
|
||||
import org.elasticsearch.xpack.sql.net.client.util.IOUtils;
|
||||
import org.jline.keymap.BindingReader;
|
||||
import org.jline.reader.EndOfFileException;
|
||||
|
@ -37,11 +38,16 @@ public class Cli {
|
|||
Cli console = new Cli(new CliConfiguration("localhost:9200/_cli", new Properties()), term);
|
||||
console.run();
|
||||
} catch (FatalException e) {
|
||||
new PrintWriter(term.output()).println(e.getMessage());
|
||||
term.writer().println(e.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "CLI application")
|
||||
private static void terminateWithError() {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final Terminal term;
|
||||
private final BindingReader bindingReader;
|
||||
|
@ -134,7 +140,7 @@ public class Cli {
|
|||
executeCommand(line, out);
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
ex.printStackTrace();
|
||||
// NOCOMMIT we should probably be able to throw these exceptions, if just for testing
|
||||
AttributedStringBuilder asb = new AttributedStringBuilder();
|
||||
asb.append("Communication error [", BOLD.foreground(RED));
|
||||
asb.append(ex.getMessage(), DEFAULT.boldOff().italic().foreground(YELLOW));
|
||||
|
@ -194,11 +200,11 @@ public class Cli {
|
|||
}
|
||||
|
||||
static class FatalException extends RuntimeException {
|
||||
public FatalException(String message, Throwable cause) {
|
||||
FatalException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public FatalException(String message) {
|
||||
FatalException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,12 @@ import org.junit.BeforeClass;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -134,9 +136,9 @@ public class CliIntegrationTestCase extends ESRestTestCase {
|
|||
@Before
|
||||
public void startCli() throws IOException {
|
||||
PipedInputStream terminalIn = new PipedInputStream();
|
||||
out = new PrintWriter(new PipedOutputStream(terminalIn), true);
|
||||
out = new PrintWriter(new OutputStreamWriter(new PipedOutputStream(terminalIn), StandardCharsets.UTF_8), true);
|
||||
PipedOutputStream terminalOut = new PipedOutputStream();
|
||||
in = new BufferedReader(new InputStreamReader(new PipedInputStream(terminalOut)));
|
||||
in = new BufferedReader(new InputStreamReader(new PipedInputStream(terminalOut), StandardCharsets.UTF_8));
|
||||
Terminal terminal = TerminalBuilder.builder()
|
||||
.system(false)
|
||||
.jansi(false)
|
||||
|
|
Loading…
Reference in New Issue