You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/06/02 01:06:00 UTC

[incubator-iotdb] branch master updated: Revert "remove echo in cli (#1287)" (#1304)

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

qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 4350fd9  Revert "remove echo in cli (#1287)" (#1304)
4350fd9 is described below

commit 4350fd916213009701142b9beee06e2b98e7b246
Author: Jialin Qiao <qj...@mails.tsinghua.edu.cn>
AuthorDate: Tue Jun 2 09:05:45 2020 +0800

    Revert "remove echo in cli (#1287)" (#1304)
    
    This reverts commit ab9e90be5dbaa1aba6254dcf5ab160239867dd69.
---
 cli/src/main/java/org/apache/iotdb/cli/Cli.java | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 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 27f5a53..dc0e967 100644
--- a/cli/src/main/java/org/apache/iotdb/cli/Cli.java
+++ b/cli/src/main/java/org/apache/iotdb/cli/Cli.java
@@ -18,9 +18,10 @@
  */
 package org.apache.iotdb.cli;
 
+import java.io.IOException;
 import java.sql.DriverManager;
 import java.sql.SQLException;
-import java.util.Scanner;
+import jline.console.ConsoleReader;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.DefaultParser;
@@ -107,15 +108,16 @@ public class Cli extends AbstractCli {
   }
 
   private static void serve() {
-    try (Scanner scanner = new Scanner(System.in)) {
+    try (ConsoleReader reader = new ConsoleReader()) {
+      reader.setExpandEvents(false);
+
       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 (password == null) {
-        print("please input your password:");
-        password = scanner.nextLine();
+        password = reader.readLine("please input your password:", '\0');
       }
       if (hasExecuteSQL) {
         try (IoTDBConnection connection = (IoTDBConnection) DriverManager
@@ -129,7 +131,7 @@ public class Cli extends AbstractCli {
         }
       }
 
-      receiveCommands(scanner);
+      receiveCommands(reader);
     } catch (ArgsErrorException e) {
       println(IOTDB_CLI_PREFIX + "> input params error because" + e.getMessage());
     } catch (Exception e) {
@@ -137,7 +139,7 @@ public class Cli extends AbstractCli {
     }
   }
 
-  private static void receiveCommands(Scanner scanner) throws TException {
+  private static void receiveCommands(ConsoleReader reader) throws TException, IOException {
     try (IoTDBConnection connection = (IoTDBConnection) DriverManager
         .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port + "/", username, password)) {
       String s;
@@ -149,8 +151,7 @@ public class Cli extends AbstractCli {
       displayLogo(properties.getVersion());
       println(IOTDB_CLI_PREFIX + "> login successfully");
       while (true) {
-        print(IOTDB_CLI_PREFIX + "> ");
-        s = scanner.nextLine();
+        s = reader.readLine(IOTDB_CLI_PREFIX + "> ", null);
         boolean continues = processCommand(s, connection);
         if (!continues) {
           break;