From 0cd0c874862822f7761f6af7d3c7482b0e26df48 Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Fri, 13 Sep 2024 13:50:50 +0200 Subject: [PATCH] Feat/cli disable history (#13461) --- .../src/main/java/org/apache/iotdb/cli/Cli.java | 8 ++++++-- .../org/apache/iotdb/cli/utils/CliContext.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java index 819cede129a..913dc2eaafd 100644 --- a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java +++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/Cli.java @@ -35,6 +35,7 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.thrift.TException; import org.jline.reader.EndOfFileException; +import org.jline.reader.LineReader; import org.jline.reader.UserInterruptException; import java.io.IOException; @@ -96,8 +97,11 @@ public class Cli extends AbstractCli { ctx.getPrinter().println(IOTDB_ERROR_PREFIX + "Exit cli with error " + e.getMessage()); ctx.exit(CODE_ERROR); } - - ctx.setLineReader(JlineUtils.getLineReader(ctx, username, host, port)); + LineReader lineReader = JlineUtils.getLineReader(ctx, username, host, port); + if (ctx.isDisableCliHistory()) { + lineReader.getVariables().put(LineReader.DISABLE_HISTORY, Boolean.TRUE); + } + ctx.setLineReader(lineReader); serve(ctx); } diff --git a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/CliContext.java b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/CliContext.java index 2085dea5a68..1edd2d928e9 100644 --- a/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/CliContext.java +++ b/iotdb-client/cli/src/main/java/org/apache/iotdb/cli/utils/CliContext.java @@ -36,14 +36,26 @@ public class CliContext { private final ExitType exitType; + private final boolean disableCliHistory; + private LineReader lineReader; public CliContext(InputStream in, PrintStream out, PrintStream err, ExitType exitType) { + this(in, out, err, exitType, false); + } + + public CliContext( + InputStream in, + PrintStream out, + PrintStream err, + ExitType exitType, + boolean disableCliHistory) { this.in = in; this.out = out; this.err = err; this.exitType = exitType; this.printer = new IoTPrinter(out); + this.disableCliHistory = disableCliHistory; } public InputStream getIn() { @@ -66,6 +78,10 @@ public class CliContext { return exitType; } + public boolean isDisableCliHistory() { + return disableCliHistory; + } + public LineReader getLineReader() { return lineReader; }