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

aradzinski pushed a commit to branch NLPCRAFT-108
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-108 by this push:
     new 0c26558  WIP.
0c26558 is described below

commit 0c265589e579d803f1d993b5c2896165ef98cc26
Author: Aaron Radzinski <[email protected]>
AuthorDate: Wed Sep 30 18:48:46 2020 -0700

    WIP.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 75 +++++++++++++++-------
 1 file changed, 52 insertions(+), 23 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
index 6bf73d2..8294075 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
@@ -17,7 +17,7 @@
 
 package org.apache.nlpcraft.model.tools.cmdline
 
-import java.io.{File, FileInputStream, IOException, ObjectInputStream}
+import java.io.{BufferedReader, File, FileInputStream, IOException, 
InputStreamReader, ObjectInputStream}
 import java.net.URL
 
 import com.google.gson._
@@ -623,7 +623,30 @@ object NCCli extends App {
      * @param args Arguments, if any, for this command.
      */
     private def cmdRepl(cmd: Command, args: Seq[Argument]): Unit = {
-        // TODO
+        logln(s"Type ${c("help")} or ${c("help -c=repl")} to get help.")
+        logln(s"Type ${c("quit")} to exit.")
+
+        val in = new BufferedReader(new InputStreamReader(System.in))
+
+        val QUITS = Seq(
+            "quit", "exit", "/q", "\\q"
+        )
+
+        var exit = false
+
+        while (!exit) {
+            log(s"${g(">")} ")
+
+            val rawLine = in.readLine()
+
+            if (rawLine == null || QUITS.contains(rawLine.trim))
+                exit = true
+            else {
+                val line = rawLine.trim()
+
+                logln(s"\nEntered: $line")
+            }
+        }
     }
 
     /**
@@ -776,45 +799,51 @@ object NCCli extends App {
         }
 
     /**
+     * Processes a single command defined by the given arguments.
      *
      * @param args
+     * @param repl Whether or not called from 'repl' command.
      */
-    private def boot(args: Array[String]): Unit = {
-        if (args.isEmpty) {
-            title()
-
-            DFLT_CMD.body(DFLT_CMD, Seq.empty)
+    private def doCommand(args: Seq[String], repl: Boolean = false): Unit = {
+        // Process 'no-ansi' command first, if any, and remove it from the 
list.
+        args.find(arg ⇒ NO_ANSI_CMD.names.contains(arg)) match {
+            case Some(_) ⇒ NO_ANSI_CMD.body(NO_ANSI_CMD, Seq.empty)
+            case None ⇒ ()
         }
-        else {
-            // Handle 'no-ansi' command right away and remove it from the list.
-            args.find(arg ⇒ NO_ANSI_CMD.names.contains(arg)) match {
-                case Some(_) ⇒ NO_ANSI_CMD.body(NO_ANSI_CMD, Seq.empty)
-                case None ⇒ ()
-            }
 
-            title()
+        // Remove 'no-ansi' command from the argument list, if any.
+        val xargs = args.filter(arg ⇒ !NO_ANSI_CMD.names.contains(arg))
 
-            val xargs = args.filter(arg ⇒ !NO_ANSI_CMD.names.contains(arg))
+        val cmd = xargs.head
 
-            val cmdName = xargs.head
-
-            CMDS.find(_.extNames.contains(cmdName)) match {
-                case Some(cmd) ⇒
+        CMDS.find(_.extNames.contains(cmd)) match {
+            case Some(cmd) ⇒
+                if (!(repl && cmd.id == "repl")) // Don't call 'repl' from 
'repl'.
                     try
                         cmd.body(cmd, processParameters(cmd, xargs.tail))
                     catch {
                         case e: Exception ⇒ error(e.getLocalizedMessage)
                     }
 
-                case None ⇒ error(s"Unknown command: $cmdName")
-            }
+            case None ⇒ error(s"Unknown command: $cmd")
         }
+    }
+
+    /**
+     *
+     * @param args
+     */
+    private def boot(args: Array[String]): Unit = {
+        title()
+
+        if (args.isEmpty)
+            DFLT_CMD.body(DFLT_CMD, Seq.empty)
+        else
+            doCommand(args.toSeq)
 
         if (exitStatus != 0)
             errorHelp()
 
-        logln()
-
         sys.exit(exitStatus)
     }
 

Reply via email to