You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2020/08/24 22:11:04 UTC
[incubator-nlpcraft] branch NLPCRAFT-108 updated: Update
NCCommandLine.scala
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 04ba731 Update NCCommandLine.scala
04ba731 is described below
commit 04ba731d0bc5f5af98354077ec9729bade539e05
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Mon Aug 24 15:10:51 2020 -0700
Update NCCommandLine.scala
---
.../model/tools/cmdline/NCCommandLine.scala | 66 +++++++++++++++++-----
1 file changed, 53 insertions(+), 13 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala
index bd408ca..fdd76ab 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCommandLine.scala
@@ -17,19 +17,19 @@
package org.apache.nlpcraft.model.tools.cmdline
+import org.apache.nlpcraft.common.util.NCUtils
import org.apache.nlpcraft.common.version.NCVersion
/**
* 'nlpcraft' script entry point.
*/
object NCCommandLine extends App {
- private final val NAME = "NLPCraft CLI"
+ private final val NAME = "Apache NLPCraft CLI"
- case class Parameter(
- names: Seq[String],
- optional: Boolean = false,
- desc: String
- )
+ private final lazy val VER = NCVersion.getCurrent
+ private final lazy val SCRIPT = NCUtils.sysEnv("NLPCRAFT_CLI_SCRIPT")
+
+ // Single CLI command.
case class Command(
name: String,
desc: String,
@@ -37,7 +37,14 @@ object NCCommandLine extends App {
examples: Seq[String] = Seq.empty,
body: (Seq[String]) => Unit
)
+ // Single command's parameter.
+ case class Parameter(
+ names: Seq[String],
+ optional: Boolean = false,
+ desc: String
+ )
+ // All supported commands.
private final val CMDS = Seq(
Command(
name = "help",
@@ -80,20 +87,53 @@ object NCCommandLine extends App {
* @param params
*/
private def cmdVersion(params: Seq[String]): Unit = {
- val curVer = NCVersion.getCurrent
-
- log(s"$NAME ver. ${curVer.version} released on ${curVer.date}")
+ // Nothing - common header with version will be printed before anyways.
}
- private def error(msg: String): Unit = System.err.println(msg)
- private def log(msg: String): Unit = System.out.println(msg)
-
+ private def error(msg: String = ""): Unit = System.err.println(msg)
+ private def log(msg: String = ""): Unit = System.out.println(msg)
+ private def errorHelp(): Unit = SCRIPT match {
+ // Running from *.{s|cmd} script.
+ case Some(script) => error(s"Run '$script ${HELP_CMD.name}' to read the manual.")
+ // Running from IDE.
+ case None => error(s"Run the process with '${HELP_CMD.name}' parameter to read the manual.")
+ }
+
/**
*
* @param args
*/
private def boot(args: Array[String]): Unit = {
-
+ var status = 0
+
+ // Print common version & copyright header.
+ log(s"$NAME ver. ${VER.version}, rel. ${VER.date}")
+ log(NCVersion.copyright)
+ log()
+
+ if (args.isEmpty)
+ NCCommandLine.DFLT_CMD.body(Seq.empty)
+ else {
+ val cmdName = args.head
+ val extCmdNames = Seq( // Safeguard against "common" errors.
+ cmdName,
+ s"-$cmdName",
+ s"--$cmdName",
+ s"/$cmdName",
+ s"\\$cmdName"
+ )
+
+ CMDS.find(c => extCmdNames.contains(c.name)) match {
+ case Some(cmd) =>
+ case None =>
+ error(s"Unknown '$cmdName' command.")
+ errorHelp()
+
+ status = 1
+ }
+ }
+
+ sys.exit(status)
}
// Boot up.