Feat/cli disable history (#13461)

This commit is contained in:
Christofer Dutz 2024-09-13 13:50:50 +02:00 committed by GitHub
parent 3f4fa64c5a
commit 0cd0c87486
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View File

@ -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);
}

View File

@ -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;
}