mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 06:46:10 +00:00
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;
|
package org.elasticsearch.xpack.sql.cli;
|
||||||
|
|
||||||
import org.elasticsearch.xpack.sql.cli.net.client.CliHttpClient;
|
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.elasticsearch.xpack.sql.net.client.util.IOUtils;
|
||||||
import org.jline.keymap.BindingReader;
|
import org.jline.keymap.BindingReader;
|
||||||
import org.jline.reader.EndOfFileException;
|
import org.jline.reader.EndOfFileException;
|
||||||
@ -37,12 +38,17 @@ public class Cli {
|
|||||||
Cli console = new Cli(new CliConfiguration("localhost:9200/_cli", new Properties()), term);
|
Cli console = new Cli(new CliConfiguration("localhost:9200/_cli", new Properties()), term);
|
||||||
console.run();
|
console.run();
|
||||||
} catch (FatalException e) {
|
} catch (FatalException e) {
|
||||||
new PrintWriter(term.output()).println(e.getMessage());
|
term.writer().println(e.getMessage());
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressForbidden(reason = "CLI application")
|
||||||
|
private static void terminateWithError() {
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
private final Terminal term;
|
private final Terminal term;
|
||||||
private final BindingReader bindingReader;
|
private final BindingReader bindingReader;
|
||||||
private final Keys keys;
|
private final Keys keys;
|
||||||
@ -134,7 +140,7 @@ public class Cli {
|
|||||||
executeCommand(line, out);
|
executeCommand(line, out);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
ex.printStackTrace();
|
// NOCOMMIT we should probably be able to throw these exceptions, if just for testing
|
||||||
AttributedStringBuilder asb = new AttributedStringBuilder();
|
AttributedStringBuilder asb = new AttributedStringBuilder();
|
||||||
asb.append("Communication error [", BOLD.foreground(RED));
|
asb.append("Communication error [", BOLD.foreground(RED));
|
||||||
asb.append(ex.getMessage(), DEFAULT.boldOff().italic().foreground(YELLOW));
|
asb.append(ex.getMessage(), DEFAULT.boldOff().italic().foreground(YELLOW));
|
||||||
@ -194,11 +200,11 @@ public class Cli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class FatalException extends RuntimeException {
|
static class FatalException extends RuntimeException {
|
||||||
public FatalException(String message, Throwable cause) {
|
FatalException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FatalException(String message) {
|
FatalException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,12 @@ import org.junit.BeforeClass;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PipedInputStream;
|
import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -134,9 +136,9 @@ public class CliIntegrationTestCase extends ESRestTestCase {
|
|||||||
@Before
|
@Before
|
||||||
public void startCli() throws IOException {
|
public void startCli() throws IOException {
|
||||||
PipedInputStream terminalIn = new PipedInputStream();
|
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();
|
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()
|
Terminal terminal = TerminalBuilder.builder()
|
||||||
.system(false)
|
.system(false)
|
||||||
.jansi(false)
|
.jansi(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user