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

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


The following commit(s) were added to refs/heads/NLPCRAFT-356 by this push:
     new 02fcee8  WIP on NLPCRAFT-356.
02fcee8 is described below

commit 02fcee85264f310b73f9e9bd48cd6e1a0aea2820
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sat Jul 3 20:25:06 2021 -0700

    WIP on NLPCRAFT-356.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 102 ++++++++-------------
 .../model/tools/cmdline/NCCliCommands.scala        |  24 +++--
 2 files changed, 53 insertions(+), 73 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 c7bfb79..7845c0d 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
@@ -258,7 +258,11 @@ object NCCli extends NCCliBase {
      * @return
      */
     private def getCpParams(args: Seq[Argument]): String =
-        U.splitTrimFilter(getParams( args, "cp").mkString(CP_SEP), 
CP_SEP).mkString(CP_SEP)
+        U.splitTrimFilter(
+            getParams( args, "cp").map(cp => 
normalizeCp(U.trimQuotes(cp))).mkString(CP_SEP),
+            CP_SEP
+        )
+        .mkString(CP_SEP)
 
     /**
      *
@@ -276,27 +280,6 @@ object NCCli extends NCCliBase {
      *
      * @param cmd
      * @param args
-     * @return
-     */
-    private def getCpParam(cmd: Command, args: Seq[Argument]): String =
-        normalizeCp(U.trimQuotes(getParam(cmd, args, "cp")))
-
-    /**
-     *
-     * @param cmd
-     * @param args
-     * @return
-     */
-    private def getCpParamOpt(cmd: Command, args: Seq[Argument]): String =
-        getParamOpt(args, "cp") match {
-            case Some(path) => normalizeCp(U.trimQuotes(path))
-            case None => null
-        }
-
-    /**
-     *
-     * @param cmd
-     * @param args
      * @param id
      * @return
      */
@@ -595,7 +578,7 @@ object NCCli extends NCCliBase {
             throw NoLocalServer()
 
         val cfgPath = getPathParam(cmd, args, "config")
-        val addCp = getCpParam(cmd, args)
+        val addCp = getCpParams(args)
         val mdls = getModelsParams(args)
         val jvmOpts = getParamOpt(args, "jvmopts") match {
             case Some(opts) => U.splitTrimFilter(U.trimQuotes(opts), " ")
@@ -621,7 +604,7 @@ object NCCli extends NCCliBase {
 
         jvmArgs += "-cp"
 
-        if (addCp != null)
+        if (addCp.nonEmpty)
             jvmArgs += s"$JAVA_CP$CP_SEP$addCp".replace(s"$CP_SEP$CP_SEP", 
CP_SEP)
         else
             jvmArgs += JAVA_CP
@@ -705,7 +688,7 @@ object NCCli extends NCCliBase {
 
         val cfgPath = getPathParam(cmd, args, "config")
         val noWait = getFlagParam(args, "noWait", dflt = false)
-        val addCp = getCpParam(cmd, args)
+        val addCp = getCpParams(args)
         val timeoutMins = getIntParam(cmd, args, "timeoutMins", 1)
         val mdls = getModelsParams(args)
         val jvmOpts = getParamOpt(args, "jvmopts") match {
@@ -735,7 +718,7 @@ object NCCli extends NCCliBase {
             prbArgs += "-Dconfig.override_with_env_vars=true"
 
         prbArgs += "-cp"
-        prbArgs += (if (addCp == null) JAVA_CP else 
s"$JAVA_CP$CP_SEP$addCp".replace(s"$CP_SEP$CP_SEP", CP_SEP))
+        prbArgs += (if (addCp.isEmpty) JAVA_CP else 
s"$JAVA_CP$CP_SEP$addCp".replace(s"$CP_SEP$CP_SEP", CP_SEP))
         prbArgs += "org.apache.nlpcraft.NCStart"
         prbArgs += "-probe"
 
@@ -1700,7 +1683,7 @@ object NCCli extends NCCliBase {
             getParam(cmd, args, "url")
         }
 
-        val addCp = getCpParamOpt(cmd, args)
+        val addCp = getCpParams(args)
         val jvmOpts = getParamOpt(args, "jvmopts") match {
             case Some(opts) => U.splitTrimFilter(U.trimQuotes(opts), " ")
             case None => Seq("-ea", "-Xms1024m")
@@ -1719,7 +1702,7 @@ object NCCli extends NCCliBase {
 
         jvmArgs += "-cp"
 
-        if (addCp != null)
+        if (addCp.nonEmpty)
             jvmArgs += s"$JAVA_CP$CP_SEP$addCp".replace(s"$CP_SEP$CP_SEP", 
CP_SEP)
         else
             jvmArgs += JAVA_CP
@@ -2347,6 +2330,12 @@ object NCCli extends NCCliBase {
             private val fsCompleter = new NCCliFileNameCompleter()
             private val cpCompleter = new NCCliModelClassCompleter()
 
+            // All '--cp' names.
+            private val CP_PARAM_NAMES = (
+                START_PRB_CMD.findParameterById("cp").names ++
+                TEST_MDL_CMD.findParameterById("cp").names
+            ).toSet
+
             /**
              *
              * @param disp
@@ -2480,43 +2469,28 @@ object NCCli extends NCCliBase {
                     })
 
                     // For 'start-probe' and 'test-model' provide model class 
name completion for '--mdls'
-                    // if '--cp' parameter with JAR file(s) is provided.
+                    // if '--cp' parameter(s) with JAR file(s) is provided.
                     if (cmd == START_PRB_CMD.name || cmd == TEST_MDL_CMD.name) 
{
-                        val cpParamNames = (
-                            START_PRB_CMD.findParameterById("cp").names ++
-                            TEST_MDL_CMD.findParameterById("cp").names
-                        ).toSet
-
-                        words.find(w => cpParamNames.exists(x => 
w.startsWith(x))) match {
-                            case Some(word) => splitEqParam(word) match {
-                                case Some((_, paramVal)) =>
-                                    var cp = paramVal.strip()
-
-                                    if (cp.head == '"' || cp.head == '\'')
-                                        cp = cp.drop(1)
-                                    if (cp.last == '"' || cp.last == '\'')
-                                        cp = cp.dropRight(1)
-
-                                    try {
-                                        for (cls <- 
cpCompleter.getModelClassNamesFromClasspath(cp.split(CP_SEP_CHAR).toSeq.asJava).asScala)
-                                            candidates.add(
-                                                mkCandidate(
-                                                    disp = "--mdls=" + cls,
-                                                    grp = OPTIONAL_GRP,
-                                                    desc = null,
-                                                    completed = true
-                                                )
-                                            )
-                                    }
-                                    catch {
-                                        // Just ignore.
-                                        case e: Exception => 
e.printStackTrace()
-                                    }
-
-                                case None => ()
-                            }
-
-                            case None => ()
+                        val cp = words.filter(w => CP_PARAM_NAMES.exists(x => 
w.startsWith(x))).flatMap(w => splitEqParam(w) match {
+                            case Some((_, paramVal)) => 
Some(U.trimQuotes(paramVal.strip()))
+                            case None => None
+                        })
+                        .mkString(CP_SEP)
+
+                        try {
+                            for (cls <- 
cpCompleter.getModelClassNamesFromClasspath(cp.split(CP_SEP_CHAR).toSeq.asJava).asScala)
+                                candidates.add(
+                                    mkCandidate(
+                                        disp = "--mdls=" + cls,
+                                        grp = OPTIONAL_GRP,
+                                        desc = null,
+                                        completed = true
+                                    )
+                                )
+                        }
+                        catch {
+                            // Just ignore.
+                            case e: Exception => ()
                         }
                     }
 
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
index ed88e0a..0d50408 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
@@ -399,6 +399,8 @@ private [cmdline] object NCCliCommands {
                         s"Although this configuration property is optional, in 
most cases you will need to provide an " +
                         s"additional classpath for JDBC driver that you use 
(see ${c("'--driver'")} parameter) unless " +
                         s"it is available in NLPCraft by default, i.e. Apache 
Ignite and H2. " +
+                        s"Note that you can have multiple ${c("'--cp'")} 
parameters and their values will be " +
+                        s"automatically combined into one final additional 
classpath. " +
                         s"Note also that you can use ${y("'~'")} at the 
beginning of the classpath component to specify user home directory."
                 ),
                 Parameter(
@@ -452,7 +454,7 @@ private [cmdline] object NCCliCommands {
                     optional = true,
                     desc =
                         s"Semicolon-separate list of tables and/or columns to 
exclude. By default, none of the " +
-                        s"tables and columns in the schema are excluded. See 
${c("--help")} parameter to get more details."
+                        s"tables and columns in the schema are excluded. See 
${c("'--help'")} parameter to get more details."
                 ),
                 Parameter(
                     id = "include",
@@ -461,7 +463,7 @@ private [cmdline] object NCCliCommands {
                     optional = true,
                     desc =
                         s"Semicolon-separate list of tables and/or columns to 
include. By default, all of the " +
-                        s"tables and columns in the schema are included. See 
${c("--help")} parameter to get more details."
+                        s"tables and columns in the schema are included. See 
${c("'--help'")} parameter to get more details."
                 ),
                 Parameter(
                     id = "prefix",
@@ -744,7 +746,9 @@ private [cmdline] object NCCliCommands {
                         s"When starting a probe with your models you must " +
                         s"provide this additional classpath for the models and 
their dependencies this probe will be hosting. " +
                         s"Parameter should include one or more classpath entry 
(JAR or directory) separated by the OS specific classpath separator. " +
-                        s"Note that you can use ${y("'~'")} at the beginning 
of the classpath component to specify user home directory."
+                        s"Note that you can have multiple ${c("'--cp'")} 
parameters and their values will be " +
+                        s"automatically combined into one final additional 
classpath. " +
+                        s"Note also that you can use ${y("'~'")} at the 
beginning of the classpath component to specify user home directory."
                 ),
                 Parameter(
                     id = "config",
@@ -767,8 +771,8 @@ private [cmdline] object NCCliCommands {
                     desc =
                         s"Comma separated list of fully qualified class names 
for models to deploy. This will override " +
                         s"${y("'nlpcraft.probe.models'")} configuration 
property from either default configuration file " +
-                        s"or the one provided by ${c("--cfg")} parameter. Note 
that you also must provide the additional " +
-                        s"classpath in this case via ${c("--cp")} parameter. 
Note also that you can have multiple '${c("--mdls")} " +
+                        s"or the one provided by ${c("'--cfg'")} parameter. 
Note that you also must provide the additional " +
+                        s"classpath in this case via ${c("'--cp'")} parameter. 
Note also that you can have multiple '${c("'--mdls'")} " +
                         s"parameters - each specifying one or more model class 
names - and they will be automatically combined together."
                 ),
                 Parameter(
@@ -856,7 +860,9 @@ private [cmdline] object NCCliCommands {
                         s"Additional JVM classpath that will be appended to 
the default NLPCraft JVM classpath. " +
                         s"When testing your models you must provide this 
additional classpath for the models and their dependencies. " +
                         s"Parameter should include one or more classpath entry 
(JAR or directory) separated by the OS specific classpath separator. " +
-                        s"Note that you can use ${y("'~'")} at the beginning 
of the classpath component to specify user home directory."
+                        s"Note that you can have multiple ${c("'--cp'")} 
parameters and their values will be " +
+                        s"automatically combined into one final additional 
classpath. " +
+                        s"Note also that you can use ${y("'~'")} at the 
beginning of the classpath component to specify user home directory."
                 ),
                 Parameter(
                     id = "config",
@@ -877,9 +883,9 @@ private [cmdline] object NCCliCommands {
                     optional = true,
                     desc =
                         s"Comma separated list of fully qualified class names 
for models to deploy and test. Note that you also " +
-                        s"must provide the additional classpath via 
${c("--cp")} parameter. If not provided, the models " +
-                        s"specified in configuration file (${c("--cfg")} 
parameter) will be used instead. Note that " +
-                        s"you can have multiple '${c("--mdls")} parameters - 
each specifying one or more model class " +
+                        s"must provide the additional classpath via 
${c("'--cp'")} parameter. If not provided, the models " +
+                        s"specified in configuration file (${c("'--cfg'")} 
parameter) will be used instead. Note that " +
+                        s"you can have multiple '${c("'--mdls'")} parameters - 
each specifying one or more model class " +
                         s"names - and they will be automatically combined 
together."
                 ),
                 Parameter(

Reply via email to