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

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


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

commit 2642a5e034dbd0b716fc09971cc5925b5909fbfe
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Jan 24 14:28:14 2021 -0800

    WIP.
---
 .../org/apache/nlpcraft/common/util/NCUtils.scala  | 67 ++++++++++++---
 .../nlpcraft/examples/sql/db/SqlServer.scala       | 11 ++-
 .../model/factories/basic/NCBasicModelFactory.java |  3 +-
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 37 +++-----
 .../model/tools/sqlgen/NCSqlModelGenerator.java    | 11 ++-
 .../sqlgen/impl/NCSqlModelGeneratorImpl.scala      | 99 +++++++++++-----------
 .../nlpcraft/server/probe/NCProbeManager.scala     |  2 +-
 .../apache/nlpcraft/common/util/NCUtilsSpec.scala  |  8 +-
 .../nlpcraft/model/tools/cmdline/NCCliSpec.scala   | 32 -------
 9 files changed, 141 insertions(+), 129 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index c6953b5..824c6be 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -55,6 +55,7 @@ import resource._
 import java.net.http.HttpClient
 import java.net.http.HttpRequest
 import java.net.http.HttpResponse
+import scala.annotation.tailrec
 import scala.collection.JavaConverters._
 import scala.collection._
 import scala.concurrent.ExecutionContext.Implicits.global
@@ -176,6 +177,22 @@ object NCUtils extends LazyLogging {
         trimFilter(s.split(sep))
 
     /**
+     * Recursively removed quotes from given string.
+     *
+     * @param s
+     * @return
+     */
+    @tailrec
+    def trimQuotes(s: String): String = {
+        val z = s.trim
+
+        if ((z.startsWith("'") && z.endsWith("'")) || (z.startsWith("\"") && 
z.endsWith("\"")))
+            trimQuotes(z.substring(1, z.length - 1))
+        else
+            z
+    }
+
+    /**
      *
      * @param s
      * @param sep
@@ -1360,27 +1377,35 @@ object NCUtils extends LazyLogging {
      * @param title
      * @param e
      */
-    def prettyError(logger: Logger, title: String, e: Throwable): Unit =
-        prettyErrorImpl(err = true, logger, title, e)
+    def prettyError(logger: Logger, title: String, e: Throwable): Unit = {
+        // Keep the full trace in the 'trace' log level.
+        logger.trace(title, e)
+
+        prettyErrorImpl(new PrettyErrorLogger {
+            override def log(s: String): Unit = logger.error(s)
+        }, title, e)
+    }
 
     /**
      *
-     * @param logger
      * @param title
      * @param e
      */
-    def prettyWarn(logger: Logger, title: String, e: Throwable): Unit =
-        prettyErrorImpl(err = false, logger, title, e)
+    def prettyError(title: String, e: Throwable): Unit =
+        prettyErrorImpl(new PrettyErrorLogger(), title, e)
+
+    sealed class PrettyErrorLogger {
+        def log(s: String) = System.err.println(s)
+    }
 
     /**
      *
-     * @param err Error or warning.
      * @param logger
      * @param title
      * @param e
      */
-    private def prettyErrorImpl(err: Boolean, logger: Logger, title: String, 
e: Throwable): Unit = {
-        if (err) logger.error(title) else logger.warn(title)
+    private def prettyErrorImpl(logger: PrettyErrorLogger, title: String, e: 
Throwable): Unit = {
+        logger.log(title)
 
         val INDENT = 2
 
@@ -1395,7 +1420,7 @@ object NCUtils extends LazyLogging {
             if (errMsg == null)
                 errMsg = "<null>"
 
-            val exClsName = if (!x.isInstanceOf[NCE]) 
s"$ansiRedFg[${x.getClass.getSimpleName}]$ansiReset " else ""
+            val exClsName = if (!x.isInstanceOf[NCE]) 
s"$ansiRedFg[${x.getClass.getCanonicalName}]$ansiReset " else ""
 
             val trace = 
x.getStackTrace.find(!_.getClassName.startsWith("scala.")).getOrElse(x.getStackTrace.head)
 
@@ -1409,13 +1434,33 @@ object NCUtils extends LazyLogging {
                     s"$exClsName$errMsg $ansiCyanFg->$ansiReset 
($fileName:$lineNum)"
 
             msg.split("\n").foreach(line ⇒ {
-                val s = s"${" " * indent}${if (first) ansiBlue("+-- ") else "  
 "}$line"
+                val s = s"${" " * indent}${if (first) ansiBlue("+-+ ") else "  
 "}${bo(y(line))}"
 
-                if (err) logger.error(s) else logger.warn(s)
+                logger.log(s)
 
                 first = false
             })
 
+            val traces = x.getStackTrace.filter {t ⇒
+                val mtdName = t.getMethodName
+                val clsName = t.getClassName
+
+                // Clean up trace.
+                clsName.startsWith("org.apache.nlpcraft") &&
+                !clsName.startsWith("org.apache.nlpcraft.common.opencensus") &&
+                !mtdName.contains("startScopedSpan") &&
+                !mtdName.contains('$')
+            }
+
+            for (trace ← traces) {
+                val fileName = trace.getFileName
+                val lineNum = trace.getLineNumber
+                val mtdName = trace.getMethodName
+                val clsName = 
trace.getClassName.replace("org.apache.nlpcraft", "o.a.n")
+
+                logger.log(s"${" " * indent}  ${b("|")} $clsName.$mtdName 
$ansiCyanFg->$ansiReset ($fileName:$lineNum)")
+            }
+
             indent += INDENT
 
             x = x.getCause
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala
index 87a40b1..349d33d 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/sql/db/SqlServer.scala
@@ -20,6 +20,7 @@ package org.apache.nlpcraft.examples.sql.db
 import java.io.File
 import java.sql.SQLException
 
+import org.apache.nlpcraft.common._
 import com.typesafe.scalalogging.LazyLogging
 import org.h2.jdbcx.JdbcDataSource
 import org.h2.tools.Server
@@ -73,12 +74,14 @@ object SqlServer extends LazyLogging {
                 if (e.getErrorCode != 42101)
                     throw e
 
-                logger.info(
-                    s"Database '$H2_URL' is NOT initialized because data 
already exists. " +
-                    s"To re-initialize - delete files in '$H2_BASEDIR' folder 
and start again. "
-                )
+                logger.info(s"Database '$H2_URL' is NOT initialized because 
data already exists.")
+                logger.info(s"  +-- To re-initialize - delete files in 
'$H2_BASEDIR' folder and start again.")
         }
 
+        logger.info(s"JDBC information:")
+        logger.info(s"  +-- ${c("URL")}: $H2_URL")
+        logger.info(s"  +-- ${c("Driver")}: org.h2.Driver")
+
         started = true
     }
     
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/factories/basic/NCBasicModelFactory.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/factories/basic/NCBasicModelFactory.java
index e9c9c72..2bdf174 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/factories/basic/NCBasicModelFactory.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/factories/basic/NCBasicModelFactory.java
@@ -68,7 +68,8 @@ public class NCBasicModelFactory implements NCModelFactory {
     @Override
     public NCModel mkModel(Class<? extends NCModel> type) {
         try {
-            return type.getConstructor().newInstance();
+            return type.getConstructor().
+                newInstance();
         }
         catch (NoSuchMethodException e) {
             throw new NCException(String.format("Model class does not have 
no-arg constructor: %s", type.getCanonicalName()), e);
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 e017c90..1ec3526 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
@@ -336,7 +336,7 @@ object NCCli extends App {
      */
     private def getParamOrNull(cmd: Command, args: Seq[Argument], id: String): 
String =
         args.find(_.parameter.id == id) match {
-            case Some(arg) ⇒ stripQuotes(arg.value.get)
+            case Some(arg) ⇒ U.trimQuotes(arg.value.get)
             case None ⇒ null
         }
 
@@ -362,7 +362,7 @@ object NCCli extends App {
      */
     private def getCpParam(cmd: Command, args: Seq[Argument], id: String): 
String =
         getParamOpt(cmd, args, id) match {
-            case Some(path) ⇒ normalizeCp(stripQuotes(path))
+            case Some(path) ⇒ normalizeCp(U.trimQuotes(path))
             case None ⇒ null
         }
 
@@ -375,7 +375,7 @@ object NCCli extends App {
      */
     private def getPathParam(cmd: Command, args: Seq[Argument], id: String, 
dflt: String = null): String = {
         def makePath(p: String): String = {
-            val normPath = refinePath(stripQuotes(p))
+            val normPath = refinePath(U.trimQuotes(p))
 
             checkFilePath(normPath)
 
@@ -400,21 +400,6 @@ object NCCli extends App {
 
     /**
      *
-     * @param s
-     * @return
-     */
-    @tailrec
-    private[cmdline] def stripQuotes(s: String): String = {
-        val x = s.trim
-
-        if ((x.startsWith("\"") && x.endsWith("\"")) || (x.startsWith("'") && 
x.endsWith("'")))
-            stripQuotes(x.substring(1, x.length - 1))
-        else
-            x
-    }
-
-    /**
-     *
      * @param path
      */
     private def checkFilePath(path: String): Unit = {
@@ -482,7 +467,7 @@ object NCCli extends App {
      */
     private [cmdline] def cmdRest(cmd: Command, args: Seq[Argument], repl: 
Boolean): Unit = {
         val restPath = getParam(cmd, args, "path") // REST call path (NOT a 
file system path).
-        val json = stripQuotes(getParam(cmd, args, "json"))
+        val json = U.trimQuotes(getParam(cmd, args, "json"))
 
         httpRest(cmd, restPath, json)
     }
@@ -498,7 +483,7 @@ object NCCli extends App {
         val noWait = getFlagParam(cmd, args, "noWait", false)
         val timeoutMins = getIntParam(cmd, args, "timeoutMins", 2)
         val jvmOpts = getParamOpt(cmd, args, "jvmopts") match {
-            case Some(opts) ⇒ U.splitTrimFilter(stripQuotes(opts), " ")
+            case Some(opts) ⇒ U.splitTrimFilter(U.trimQuotes(opts), " ")
             case None ⇒ Seq("-ea", "-Xms2048m", "-XX:+UseG1GC")
         }
 
@@ -694,7 +679,7 @@ object NCCli extends App {
         val addCp = getCpParam(cmd, args, "cp")
         val mdls = getParamOrNull(cmd, args, "models")
         val jvmOpts = getParamOpt(cmd, args, "jvmopts") match {
-            case Some(opts) ⇒ U.splitTrimFilter(stripQuotes(opts), " ")
+            case Some(opts) ⇒ U.splitTrimFilter(U.trimQuotes(opts), " ")
             case None ⇒ Seq("-ea", "-Xms1024m")
         }
 
@@ -780,7 +765,7 @@ object NCCli extends App {
         val timeoutMins = getIntParam(cmd, args, "timeoutMins", 1)
         val mdls = getParamOrNull(cmd, args, "models")
         val jvmOpts = getParamOpt(cmd, args, "jvmopts") match {
-            case Some(opts) ⇒ U.splitTrimFilter(stripQuotes(opts), " ")
+            case Some(opts) ⇒ U.splitTrimFilter(U.trimQuotes(opts), " ")
             case None ⇒ Seq("-ea", "-Xms1024m")
         }
 
@@ -1757,7 +1742,7 @@ object NCCli extends App {
 
         val addCp = getCpParam(cmd, args, "cp")
         val jvmOpts = getParamOpt(cmd, args, "jvmopts") match {
-            case Some(opts) ⇒ U.splitTrimFilter(stripQuotes(opts), " ")
+            case Some(opts) ⇒ U.splitTrimFilter(U.trimQuotes(opts), " ")
             case None ⇒ Seq("-ea", "-Xms1024m")
         }
 
@@ -1904,8 +1889,8 @@ object NCCli extends App {
                     val value = arg.value.getOrElse(throw 
InvalidJsonParameter(cmd, arg.parameter.names.head))
 
                     param.kind match {
-                        case STRING ⇒ buf ++= "\"" + 
U.escapeJson(stripQuotes(value)) + "\""
-                        case OBJECT | ARRAY ⇒ buf ++= stripQuotes(value)
+                        case STRING ⇒ buf ++= "\"" + 
U.escapeJson(U.trimQuotes(value)) + "\""
+                        case OBJECT | ARRAY ⇒ buf ++= U.trimQuotes(value)
                         case BOOLEAN | NUMERIC ⇒ buf ++= value
                     }
 
@@ -2932,7 +2917,7 @@ object NCCli extends App {
                 throw mkError()
 
             val name = if (parts.size == 1) arg.trim else parts(0).trim
-            val value = if (parts.size == 1) None else 
Some(stripQuotes(parts(1).trim))
+            val value = if (parts.size == 1) None else 
Some(U.trimQuotes(parts(1).trim))
             val hasSynth = cmd.params.exists(_.synthetic)
 
             if (name.endsWith("=")) // Missing value or extra '='.
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/NCSqlModelGenerator.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/NCSqlModelGenerator.java
index bac3276..9045526 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/NCSqlModelGenerator.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/NCSqlModelGenerator.java
@@ -17,6 +17,7 @@
 
 package org.apache.nlpcraft.model.tools.sqlgen;
 
+import org.apache.nlpcraft.common.util.NCUtils;
 import org.apache.nlpcraft.model.*;
 import org.apache.nlpcraft.common.NCException;
 import org.apache.nlpcraft.model.tools.sqlgen.impl.*;
@@ -57,16 +58,18 @@ public class NCSqlModelGenerator {
     /**
      * Runs SQL model generator with given command line parameters.
      * 
-     * @param args Command line parameters. Execute with <code>--help</code> 
parameter to get a full
-     *      documentation.
+     * @param args Command line parameters. Execute with <code>--help</code> 
parameter to get a full documentation.
      * @throws NCException Thrown in case of any errors.
      */
     public static void main(String[] args) {
-        int status  = 0;
+
+        boolean fromCli = NCUtils.isSysEnvSet("NLPCRAFT_FROM_CLI");
+
+        int status = 0;
 
         // Calling out Scala engine.
         try {
-            NCSqlModelGeneratorImpl.process(false, args);
+            NCSqlModelGeneratorImpl.process(fromCli, args);
         }
         catch (Exception e) {
             status = 1;
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImpl.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImpl.scala
index 0b66262..f234be3 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImpl.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/sqlgen/impl/NCSqlModelGeneratorImpl.scala
@@ -45,7 +45,7 @@ import scala.util.Try
  * Scala-based SQL model engine.
  */
 object NCSqlModelGeneratorImpl {
-    private var repl = false
+    private var fromCli = false
 
     case class Join(
         fromColumns: Seq[String],
@@ -592,8 +592,8 @@ object NCSqlModelGeneratorImpl {
     /**
      *
       */
-    private def help(out: PrintStream): Unit =
-        out.println(
+    private def help(): Unit =
+        System.out.println(
             s"""
                |${bo("NAME:")}
                |    ${c("NCSqlModelGenerator")} -- NLPCraft model generator 
from SQL databases.
@@ -613,68 +613,68 @@ object NCSqlModelGeneratorImpl {
                |    this application.
                |
                |${bo("PARAMETERS:")}
-               |    ${c("--url|-r")} ${g("url")}
+               |    ${c("--url|-r")}=${g("url")}
                |        Mandatory database JDBC URL.
                |
-               |    ${c("--driver|-d")} ${g("class")}
+               |    ${c("--driver|-d")}=${g("class")}
                |        Mandatory JDBC driver class. Note that 'class' must be 
a
                |        fully qualified class name. It should also be 
available on
                |        the classpath.
                |
-               |    ${c("--schema|-s")} ${g("schema")}
+               |    ${c("--schema|-s")}=${g("schema")}
                |        Mandatory database schema to scan.
                |
-               |    ${c("--out|-o")} ${g("filename")}
+               |    ${c("--out|-o")}=${g("filename")}
                |        Mandatory name of the output JSON or YAML model file. 
It should
                |        have one of the following extensions: .js, .json, 
.yml, or .yaml
                |        File extension determines the output file format.
                |
-               |    ${c("--user|-u")} ${g("username")}
+               |    ${c("--user|-u")}=${g("username")}
                |        Optional database user name.
                |
-               |    ${c("--password|-w")} ${g("password")}
+               |    ${c("--password|-w")}=${g("password")}
                |        Optional database user password.
                |
-               |    ${c("--mdlId|-m")} ${g("id")}
+               |    ${c("--mdlId|-m")}=${g("id")}
                |        Optional generated model ID. By default, the model ID 
will be 'sql.model.id'.
                |
-               |    ${c("--mdlVer|-v")} ${g("version")}
+               |    ${c("--mdlVer|-v")}=${g("version")}
                |        Optional generated model version. By default, the 
model version will be '1.0.0-timestamp'.
                |
-               |    ${c("--mdlName|-n")} ${g("name")}
+               |    ${c("--mdlName|-n")}=${g("name")}
                |        Optional generated model name. By default, the model 
name will be 'SQL-based model'.
                |
-               |    ${c("--exclude|-e")} ${g("list")}
+               |    ${c("--exclude|-e")}=${g("list")}
                |        Optional semicolon-separate list of tables and/or 
columns to exclude. By
                |        default, none of the tables and columns in the schema 
are excluded. See below
                |        for more information.
                |
-               |    ${c("--prefix|-f")} ${g("list")}
+               |    ${c("--prefix|-f")}=${g("list")}
                |        Optional comma-separate list of table or column name 
prefixes to remove.
                |        These prefixes will be removed when name is used for 
model elements
                |        synonyms. By default, no prefixes will be removed.
                |
-               |    ${c("--suffix|-q")} ${g("list")}
+               |    ${c("--suffix|-q")}=${g("list")}
                |        Optional comma-separate list of table or column name 
suffixes to remove.
                |        These suffixes will be removed when name is used for 
model elements
                |        synonyms. By default, no suffixes will be removed.
                |
-               |    ${c("--include|-i")} ${g("list")}
+               |    ${c("--include|-i")}=${g("list")}
                |        Optional semicolon-separate list of tables and/or 
columns to include. By
                |        default, all tables and columns in the schema are 
included. See below
                |        for more information.
                |
-               |    ${c("--synonyms|-y")} ${g("true|false")}
+               |    ${c("--synonyms|-y")}=${g("true|false")}
                |        Optional flag on whether or not to generated auto 
synonyms for the model elements.
                |        Default is true.
                |
-               |    ${c("--override|-z")} ${g("true|false")}
+               |    ${c("--override|-z")}=${g("true|false")}
                |        Optional flag to determine whether or not to override 
output file if it already exist.
                |        If override is disabled (default) and output file 
exists - a unique file name will
                |        be used instead.
                |        Default is false.
                |
-               |    ${c("--parent|-p")} ${g("true|false")}
+               |    ${c("--parent|-p")}=${g("true|false")}
                |        Optional flag on whether or not to use element's 
parent relationship for
                |        defining SQL columns and their containing (i.e. 
parent) tables.
                |        Default is false.
@@ -685,6 +685,9 @@ object NCSqlModelGeneratorImpl {
                |${bo("DETAILS:")}
                |    ${c("-r")}, ${c("-d")}, ${c("-s")}, and ${c("-o")} are 
mandatory parameters, everything else is optional.
                |
+               |    Parameter values can be placed in double (") or single (') 
quotes which will be
+               |    automatically discarded. Use it to pass strings containing 
spaces in the command line.
+               |
                |    Each -i or -e parameter is a semicolon ';' separated  list 
of table or columns names.
                |    Each table or column name can be one of following forms:
                |      - ${g("table")}         -- to filter on table names only.
@@ -694,20 +697,20 @@ object NCSqlModelGeneratorImpl {
                |    Table and column names are treated as standard Java 
regular expressions. Note that
                |    both '#' and ';' cannot be used inside of the regular 
expression:
                |
-               |    ${c("-e")} "${g("#_.+")}"             -- excludes any 
columns starting with '_'.
-               |    ${c("-e")} "${g("tmp.+")}"            -- excludes all 
tables starting with 'tmp'.
-               |    ${c("-i")} "${g("Order.*;#[^_].+")}"  -- includes only 
tables starting with 'Order' and columns that
+               |    ${c("-e")}="${g("#_.+")}"             -- excludes any 
columns starting with '_'.
+               |    ${c("-e")}="${g("tmp.+")}"            -- excludes all 
tables starting with 'tmp'.
+               |    ${c("-i")}="${g("Order.*;#[^_].+")}"  -- includes only 
tables starting with 'Order' and columns that
                |                             do not start with '_'.
                |
                |${bo("EXAMPLES:")}
                |    java -cp 
apache-nlpcraft-incubating-${ver.version}-all-deps.jar 
org.apache.nlpcraft.model.tools.sqlgen.NCSqlModelGenerator
-               |        ${c("-r")} jdbc:postgresql://localhost:5432/mydb
-               |        ${c("-d")} org.postgresql.Driver
-               |        ${c("-f")} "tbl_, col_"
-               |        ${c("-q")} "_tmp, _old, _unused"
-               |        ${c("-s")} public
-               |        ${c("-e")} "#_.+"
-               |        ${c("-o")} model.json
+               |        ${c("-r")}=jdbc:postgresql://localhost:5432/mydb
+               |        ${c("-d")}=org.postgresql.Driver
+               |        ${c("-f")}="tbl_, col_"
+               |        ${c("-q")}="_tmp, _old, _unused"
+               |        ${c("-s")}=public
+               |        ${c("-e")}="#_.+"
+               |        ${c("-o")}=model.json
                 """.stripMargin
         )
     
@@ -716,20 +719,12 @@ object NCSqlModelGeneratorImpl {
      * @param msg Optional error message.
      */
     private def errorExit(msg: String = null): Unit = {
-        if (repl)
-            throw new Exception(msg)
-        else {
-            if (msg != null)
-                System.err.println(
-                    s"""
-                       |${r("ERROR:")}
-                       |    $msg""".stripMargin
-                )
+        System.err.println(s"${r("X:")} $msg")
 
-            help(System.err)
+        if (!fromCli)
+            help()
 
-            throw new Exception(msg)
-        }
+        throw new Exception(msg)
     }
     
     /**
@@ -751,7 +746,7 @@ object NCSqlModelGeneratorImpl {
         v.toLowerCase match {
             case "true" ⇒ true
             case "false" ⇒ false
-            case _ ⇒ throw new IllegalArgumentException(s"Invalid boolean 
value: $C$name $v$RST")
+            case _ ⇒ throw new IllegalArgumentException(s"Invalid boolean 
value: $C$name=$v$RST")
         }
         
     /**
@@ -766,8 +761,14 @@ object NCSqlModelGeneratorImpl {
         
         try {
             while (i < cmdArgs.length - 1) {
-                val k = cmdArgs(i).toLowerCase
-                val v = cmdArgs(i + 1)
+                val arg = cmdArgs(i)
+                val eq = arg.indexOf('=')
+
+                if (eq == -1)
+                    throw new IllegalArgumentException(s"Invalid argument: 
$C$arg$RST")
+
+                val k: String = arg.substring(0, eq)
+                val v: String = U.trimQuotes(arg.substring(eq + 1))
 
                 k match {
                     case "--url" | "-r" ⇒ params.url = v
@@ -787,7 +788,7 @@ object NCSqlModelGeneratorImpl {
                     case "--synonyms" | "-y" ⇒ params.synonyms = 
parseBoolean(v, k)
                     case "--override" | "-z" ⇒ params.overRide = 
parseBoolean(v, k)
 
-                    case _ ⇒ throw new IllegalArgumentException(s"Invalid 
argument: $C${cmdArgs(i)}$RST")
+                    case _ ⇒ throw new IllegalArgumentException(s"Invalid 
argument: $C$arg$RST")
                 }
 
                 i = i + 2
@@ -817,14 +818,14 @@ object NCSqlModelGeneratorImpl {
 
     /**
      *
-     * @param repl Whether or not this is called from REPL.
+     * @param fromCli Whether or not this tool was called from NLPCraft CLI.
      * @param args Command line arguments.
      */
-    def process(repl: Boolean, args: Array[String]): Unit = {
-        this.repl = repl
+    def process(fromCli: Boolean, args: Array[String]): Unit = {
+        this.fromCli = fromCli
 
         if (args.isEmpty || !args.intersect(Seq("--help", "-h", "-help", 
"--?", "-?", "/?", "/help")).isEmpty)
-            help(System.out)
+            help()
         else {
             val params = parseCmdParameters(args)
             val tbls = readSqlMetadata(params)
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
index 8e210ac..d54ef7c 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
@@ -405,7 +405,7 @@ object NCProbeManager extends NCService {
                                 val ms = Config.reconnectTimeoutMs
     
                                 // Server socket error must be logged.
-                                U.prettyWarn(logger, s"$name server error, 
re-starting in ${ms / 1000} sec.", e)
+                                U.prettyError(logger, s"$name server error, 
re-starting in ${ms / 1000} sec.", e)
                                 
                                 U.sleep(ms)
                             }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
index 4a4ed27..68d8d88 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
@@ -18,7 +18,7 @@
 package org.apache.nlpcraft.common.util
 
 import org.apache.nlpcraft.common._
-import org.junit.jupiter.api.Assertions.assertTrue
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
 import org.junit.jupiter.api.Test
 
 /**
@@ -46,6 +46,12 @@ class NCUtilsSpec  {
     }
 
     @Test
+    def testTrimQuotes() = {
+        assertEquals(U.trimQuotes("""'x'"""), "x")
+        assertEquals(U.trimQuotes("""'"'x'" "z"'"""), """'x'" "z""")
+    }
+
+    @Test
     def testGetDups() {
         assertTrue(U.getDups(Seq("a", "b", "a")) == Set("a"))
         assertTrue(U.getDups(Seq("a", "a", "a", "b", "a")) == Set("a"))
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliSpec.scala
deleted file mode 100644
index cbee4b4..0000000
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliSpec.scala
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.nlpcraft.model.tools.cmdline
-
-import org.junit.jupiter.api.Assertions._
-import org.junit.jupiter.api.Test
-
-/**
- * Various tests for `NCCli` class.
- */
-class NCCliSpec {
-    @Test
-    def testStripQuotes(): Unit = {
-        assertEquals(NCCli.stripQuotes("""'x'"""), "x")
-        assertEquals(NCCli.stripQuotes("""'"'x'" "z"'"""), """'x'" "z""")
-    }
-}

Reply via email to