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 a2b33ee WIP.
a2b33ee is described below
commit a2b33eeeb86e21d185fafd985ddf65878b767251
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Jan 24 15:08:41 2021 -0800
WIP.
---
.../model/tools/sqlgen/NCSqlModelGenerator.java | 5 +--
.../sqlgen/impl/NCSqlModelGeneratorImpl.scala | 43 +++++++++-------------
2 files changed, 19 insertions(+), 29 deletions(-)
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 9045526..b913747 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
@@ -62,14 +62,11 @@ public class NCSqlModelGenerator {
* @throws NCException Thrown in case of any errors.
*/
public static void main(String[] args) {
-
- boolean fromCli = NCUtils.isSysEnvSet("NLPCRAFT_FROM_CLI");
-
int status = 0;
// Calling out Scala engine.
try {
- NCSqlModelGeneratorImpl.process(fromCli, args);
+ NCSqlModelGeneratorImpl.process(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 f234be3..6ca9e05 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
@@ -17,7 +17,7 @@
package org.apache.nlpcraft.model.tools.sqlgen.impl
-import java.io.{File, FileOutputStream, IOException, PrintStream}
+import java.io.{File, FileOutputStream, IOException}
import java.sql.{Connection, DriverManager, ResultSet}
import java.time.format.DateTimeFormatter
import java.time.{Instant, LocalDateTime}
@@ -45,8 +45,6 @@ import scala.util.Try
* Scala-based SQL model engine.
*/
object NCSqlModelGeneratorImpl {
- private var fromCli = false
-
case class Join(
fromColumns: Seq[String],
toTable: String,
@@ -57,7 +55,7 @@ object NCSqlModelGeneratorImpl {
val nameLc: String
val elmNameLc: String
- private val nameWs = U.normalize(elmNameLc.replaceAll("_"," ")," ")
+ private lazy val nameWs = U.normalize(elmNameLc.replaceAll("_"," "),"
")
lazy val synonym =
if (elmNameLc == nameWs)
@@ -395,14 +393,14 @@ object NCSqlModelGeneratorImpl {
file = new File(file.getParent, s"${name}_$unique.$ext")
println(
- s"Output file already exist and override is disabled:\n" +
- s" +-→ using $C'${file.getName}'$RST filename instead."
+ s"Output file already exist and override is disabled
($C-z=false$RST):\n" +
+ s" $G+--$RST using $C'${file.getName}'$RST filename
instead."
)
}
else
println(
s"Existing file '${file.getName}' will be overridden:\n" +
- s" +-→ use $C'-z false'$RST to disable override."
+ s" $G+--$RST use $C'-z=false'$RST to disable override."
)
}
@@ -414,7 +412,7 @@ object NCSqlModelGeneratorImpl {
}
}
catch {
- case e: IOException ⇒ errorExit(s"Failed to write output file
'${file.getAbsolutePath}': ${e.getMessage}")
+ case e: IOException ⇒ errorExit(s"Failed to write output file:
$C'${file.getAbsolutePath}'$RST", e)
}
val tbl = NCAsciiTable()
@@ -438,7 +436,7 @@ object NCSqlModelGeneratorImpl {
tbl += ("Columns scanned", tables.flatMap(_.columns).size)
tbl += ("Model elements", elems.size)
- println(s"Model generated: ${file.getAbsolutePath}")
+ println(s"Model generated: $G${file.getAbsolutePath}$RST")
println(tbl)
@@ -582,8 +580,8 @@ object NCSqlModelGeneratorImpl {
}
}
catch {
- case _: ClassNotFoundException ⇒ errorExit(s"Unknown JDBC driver
class: $C${params.driver}$RST")
- case e: Exception ⇒ errorExit(s"Failed to generate model for
$C'${params.url}'$RST: ${e.getLocalizedMessage}")
+ case e: ClassNotFoundException ⇒ errorExit(s"Unknown JDBC driver
class: $C${params.driver}$RST", e)
+ case e: Exception ⇒ errorExit(s"Failed to generate model for:
$C'${params.url}'$RST", e)
}
tables.values.toSeq.filter(_.columns.nonEmpty)
@@ -716,15 +714,13 @@ object NCSqlModelGeneratorImpl {
/**
*
- * @param msg Optional error message.
+ * @param msg Error message.
+ * @param e Cause exception.
*/
- private def errorExit(msg: String = null): Unit = {
- System.err.println(s"${r("X:")} $msg")
-
- if (!fromCli)
- help()
+ private def errorExit(msg: String, e: Throwable): Unit = {
+ U.prettyError(s"${R}X:$RST $msg", e)
- throw new Exception(msg)
+ throw new Exception(msg, e)
}
/**
@@ -760,7 +756,7 @@ object NCSqlModelGeneratorImpl {
var i = 0
try {
- while (i < cmdArgs.length - 1) {
+ while (i < cmdArgs.length) {
val arg = cmdArgs(i)
val eq = arg.indexOf('=')
@@ -791,7 +787,7 @@ object NCSqlModelGeneratorImpl {
case _ ⇒ throw new IllegalArgumentException(s"Invalid
argument: $C$arg$RST")
}
- i = i + 2
+ i += 1
}
mandatoryParam(params.url, "--url")
@@ -810,7 +806,7 @@ object NCSqlModelGeneratorImpl {
params.cmdLine = cmdArgs.mkString(" ")
}
catch {
- case e: Exception ⇒ errorExit(e.getMessage)
+ case e: Exception ⇒ errorExit(e.getMessage, e)
}
params
@@ -818,12 +814,9 @@ object NCSqlModelGeneratorImpl {
/**
*
- * @param fromCli Whether or not this tool was called from NLPCraft CLI.
* @param args Command line arguments.
*/
- def process(fromCli: Boolean, args: Array[String]): Unit = {
- this.fromCli = fromCli
-
+ def process(args: Array[String]): Unit = {
if (args.isEmpty || !args.intersect(Seq("--help", "-h", "-help",
"--?", "-?", "/?", "/help")).isEmpty)
help()
else {