You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/01/14 11:42:53 UTC

[iotdb] 01/01: [IOTDB-2287] Separate CLI history by different IoTDB users

This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch iotdb_jline
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit fc9948af4878fa3f0db8b4d0f3ed26fd9bea5f63
Author: HTHou <hh...@outlook.com>
AuthorDate: Fri Jan 14 19:41:58 2022 +0800

    [IOTDB-2287] Separate CLI history by different IoTDB users
---
 cli/src/main/java/org/apache/iotdb/cli/Cli.java              | 11 +++++++++--
 cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java |  4 ++--
 cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java       |  2 +-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/cli/src/main/java/org/apache/iotdb/cli/Cli.java b/cli/src/main/java/org/apache/iotdb/cli/Cli.java
index 6d7675f..0cbf039 100644
--- a/cli/src/main/java/org/apache/iotdb/cli/Cli.java
+++ b/cli/src/main/java/org/apache/iotdb/cli/Cli.java
@@ -76,7 +76,15 @@ public class Cli extends AbstractCli {
       return;
     }
 
-    lineReader = JlineUtils.getLineReader();
+    try {
+      username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
+    } catch (ArgsErrorException e) {
+      println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
+    } catch (Exception e) {
+      println(IOTDB_CLI_PREFIX + "> exit cli with error " + e.getMessage());
+    }
+
+    lineReader = JlineUtils.getLineReader(username);
     serve();
   }
 
@@ -117,7 +125,6 @@ public class Cli extends AbstractCli {
     try {
       host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
       port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
-      username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
 
       password = commandLine.getOptionValue(PASSWORD_ARGS);
       if (hasExecuteSQL && password != null) {
diff --git a/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java b/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
index 2cfc96e..139a2fe 100644
--- a/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
+++ b/cli/src/main/java/org/apache/iotdb/cli/utils/JlineUtils.java
@@ -50,7 +50,7 @@ public class JlineUtils {
           .filter(w -> SQL_KEYWORD_PATTERN.matcher(w).matches())
           .collect(Collectors.toSet());
 
-  public static LineReader getLineReader() throws IOException {
+  public static LineReader getLineReader(String username) throws IOException {
     // Defaulting to a dumb terminal when a supported terminal can not be correctly created
     // see https://github.com/jline/jline3/issues/291
     Terminal terminal = TerminalBuilder.builder().dumb(true).build();
@@ -70,7 +70,7 @@ public class JlineUtils {
     // size of the history fill will be less than 10 KB. See:
     // org.jline.reader.impl.history#DefaultHistory
     String historyFile = ".iotdb.history";
-    String historyFilePath = System.getProperty("user.home") + File.separator + historyFile;
+    String historyFilePath = System.getProperty("user.home") + File.separator + username + historyFile;
     builder.variable(LineReader.HISTORY_FILE, new File(historyFilePath));
 
     // TODO: since the lexer doesn't produce tokens for quotation marks, disable the highlighter to
diff --git a/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java b/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java
index efd4d7b..3ea31cb 100644
--- a/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java
+++ b/cli/src/main/java/org/apache/iotdb/tool/ExportCsv.java
@@ -133,7 +133,7 @@ public class ExportCsv extends AbstractCsvTool {
         String sql;
 
         if (sqlFile == null) {
-          LineReader lineReader = JlineUtils.getLineReader();
+          LineReader lineReader = JlineUtils.getLineReader(username);
           sql = lineReader.readLine(TSFILEDB_CLI_PREFIX + "> please input query: ");
           System.out.println(sql);
           String[] values = sql.trim().split(";");