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 a71f3f1 WIP.
a71f3f1 is described below
commit a71f3f1fc1fc42a912f48daa896ebb5758a53280
Author: Aaron Radzinski <[email protected]>
AuthorDate: Thu Aug 27 23:25:58 2020 -0700
WIP.
---
.../model/tools/cmdline/NCCommandLine.scala | 111 ++++++++++++++++-----
.../sqlgen/impl/NCSqlModelGeneratorImpl.scala | 36 +++----
2 files changed, 102 insertions(+), 45 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 cc1ced9..6fcbf52 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
@@ -20,7 +20,6 @@ package org.apache.nlpcraft.model.tools.cmdline
import org.apache.nlpcraft.common.ascii.NCAsciiTable
import org.apache.nlpcraft.common.util.NCUtils
import org.apache.nlpcraft.common.version.NCVersion
-
import scala.collection.mutable
/**
@@ -110,8 +109,8 @@ object NCCommandLine extends App {
),
examples = Seq(
Example(
- code = s"$$ $SCRIPT_NAME help repl",
- desc = "Displays help for 'repl' command."
+ code = s"$$ $SCRIPT_NAME help -c=repl --cmd=ver",
+ desc = "Displays help for 'repl' and 'version' commands."
),
Example(
code = s"$$ $SCRIPT_NAME help -all",
@@ -130,14 +129,14 @@ object NCCommandLine extends App {
params = Seq(
Parameter(
id = "semver",
- names = Seq("--semver", "-s"),
+ names = Seq("--sem-ver", "-s"),
valueDesc = None,
optional = true,
desc = s"Display only the semantic version value, e.g.
${VER.version}."
),
Parameter(
id = "reldate",
- names = Seq("--reldate", "-d"),
+ names = Seq("--rel-date", "-d"),
valueDesc = None,
optional = true,
desc = s"Display only the release date, e.g. ${VER.date}."
@@ -156,6 +155,30 @@ object NCCommandLine extends App {
private final val DFLT_CMD = CMDS.find(_.id == "repl").get
/**
+ *
+ * @param param Expected parameter.
+ * @param str String to parse.
+ * @return
+ */
+ private def getParamValue(param: Parameter, str: String): Option[String] =
{
+ val arr = str.split("=")
+
+ if (arr.size != 2) {
+ error(s"Invalid parameter format: $str")
+
+ None
+ }
+ else if (!param.names.contains(arr.head)) {
+ error(s"Unknown parameter in: $str")
+
+ None
+
+ }
+ else
+ Some(arr.last)
+ }
+
+ /**
* @param cmd Command descriptor.
* @param params Parameters, if any, for this command.
*/
@@ -193,12 +216,20 @@ object NCCommandLine extends App {
lines += "PARAMETERS:"
for (param <- cmd.params) {
- var nameLine = s"$T___${param.names.mkString(", ")}"
-
if (param.valueDesc.isDefined)
- nameLine += s"=${param.valueDesc.get}"
-
- lines += nameLine
+ lines += T___ +
param.names.zip(Stream.continually(param.valueDesc.get)).map(t =>
s"${t._1}=${t._2}").mkString(", ")
+ else
+ lines += s"$T___${param.names.mkString(", ")}"
+//
+//
+//
+//
+// var nameLine = s"$T___${param.names.mkString(", ")}"
+//
+// if (param.valueDesc.isDefined)
+// nameLine += s"=${param.valueDesc.get}"
+//
+// lines += nameLine
if (param.optional)
lines += s"$T___${T___}Optional."
@@ -233,7 +264,8 @@ object NCCommandLine extends App {
))
log(tbl.toString)
- } else if (cmd.isParamPresent("all", params)) { // Show a full format
help for all commands.
+ }
+ else if (cmd.isParamPresent("all", params)) { // Show a full format
help for all commands.
header()
CMDS.foreach(cmd =>
@@ -244,27 +276,39 @@ object NCCommandLine extends App {
)
log(tbl.toString)
- } else {
+ }
+ else { // Help for individual commands.
+ var err = false
+ val cmdParam = cmd.params.find(_.id == "cmd").get
+ val seen = mutable.Buffer.empty[String]
+ // At this point it should only be '--cmd' parameters.
for (param <- params) {
- var err = false
-
- CMDS.find(_.names.contains(param)) match {
- case Some(cmd) =>
- tbl +/ (
- "" -> cmd.names.mkString(", "),
- "align:left, maxWidth:65" -> mkCmdLines(cmd)
- )
- case None =>
- err = true
- error(s"Unknown command to get help for: $param")
+ getParamValue(cmdParam, param) match {
+ case Some(value) =>
+ CMDS.find(_.names.contains(value)) match {
+ case Some(c) =>
+ if (!seen.contains(c.id)) {
+ tbl +/ (
+ "" -> c.names.mkString(", "),
+ "align:left, maxWidth:65" ->
mkCmdLines(c)
+ )
+
+ seen += c.id
+ }
+ case None =>
+ err = true
+ error(s"Unknown command '$value' to get help
for in: $param")
+ }
+
+ case None => err = true
}
+ }
- if (!err) {
- header()
+ if (!err) {
+ header()
- log(tbl.toString)
- }
+ log(tbl.toString)
}
}
}
@@ -276,6 +320,8 @@ object NCCommandLine extends App {
*/
private def cmdRepl(cmd: Command, params: Seq[String]): Unit = {
title()
+
+ // TODO
}
/**
@@ -301,6 +347,10 @@ object NCCommandLine extends App {
}
+ /**
+ *
+ * @param msg
+ */
private def error(msg: String = ""): Unit = {
// Make sure we exit with non-zero status.
exitStatus = 1
@@ -308,8 +358,15 @@ object NCCommandLine extends App {
System.err.println(s"ERROR: $msg")
}
+ /**
+ *
+ * @param 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.mainName}' to
read the manual.")
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 e9eea70..f130544 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
@@ -49,6 +49,19 @@ object NCSqlModelGeneratorImpl {
toTable: String,
toColumns: Seq[String]
)
+
+ trait NamedEntity {
+ val nameLc: String
+ val elmNameLc: String
+
+ private val nameWs = elmNameLc.replaceAll("_", " ").split("
").filter(_.nonEmpty).mkString(" ")
+
+ lazy val synonym =
+ if (elmNameLc == nameWs)
+ substituteMacros(elmNameLc)
+ else
+
s"{${substituteMacros(elmNameLc)}|${substituteMacros(removeSeqDups(nameWs))}}"
+ }
//
https://docs.oracle.com/javase/8/docs/api/java/sql/DatabaseMetaData.html#getColumns-java.lang.String-java.lang.String-java.lang.String-java.lang.String-
case class Column(
@@ -57,17 +70,11 @@ object NCSqlModelGeneratorImpl {
dataType: Int,
isNullable: String,
isPk: Boolean
- ) {
+ ) extends NamedEntity {
val nameLc = name.toLowerCase()
val elmNameLc = elmName.toLowerCase()
- private val nameWs = elmNameLc.replaceAll("_", " ").split("
").filter(_.nonEmpty).mkString(" ")
-
+
lazy val isNull = isNullable == "YES"
- lazy val synonym =
- if (elmNameLc == nameWs)
- substituteMacros(elmNameLc)
- else
-
s"{${substituteMacros(elmNameLc)}|${substituteMacros(removeSeqDups(nameWs))}}"
}
case class Table(
@@ -75,16 +82,9 @@ object NCSqlModelGeneratorImpl {
elmName: String, // Name with optionally removed prefix and suffix.
joins: Seq[Join],
columns: mutable.ArrayBuffer[Column] =
mutable.ArrayBuffer.empty[Column]
- ) {
+ ) extends NamedEntity {
val nameLc = name.toLowerCase()
val elmNameLc = elmName.toLowerCase()
- private val nameWs = elmNameLc.replaceAll("_", " ").split("
").filter(_.nonEmpty).mkString(" ")
-
- lazy val synonym =
- if (elmNameLc == nameWs)
- substituteMacros(elmNameLc)
- else
-
s"{${substituteMacros(elmNameLc)}|${substituteMacros(removeSeqDups(nameWs))}}"
}
case class ParametersHolder(
@@ -348,9 +348,9 @@ object NCSqlModelGeneratorImpl {
def forall(seq: Seq[Boolean], v: Boolean): Boolean =
seq.forall(_ == v)
val typ =
- if (forall(fromColsNulls, true) && forall(toColsNulls,
false))
+ if (forall(fromColsNulls, v = true) &&
forall(toColsNulls, v = false))
NCSqlJoinType.LEFT
- else if (forall(fromColsNulls, false) &&
forall(toColsNulls, true))
+ else if (forall(fromColsNulls, v = false) &&
forall(toColsNulls, v = true))
NCSqlJoinType.RIGHT
else
// Default value.