This is an automated email from the ASF dual-hosted git repository. aradzinski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 4ff4bd6f31d5c7fd0f0759fd3ec6cc678e034a91 Author: Aaron Radzinski <[email protected]> AuthorDate: Sat Dec 19 16:51:53 2020 -0800 WIP. --- .../nlpcraft/model/tools/cmdline/NCCli.scala | 63 +++++++++------------- .../sqlgen/impl/NCSqlModelGeneratorImpl.scala | 14 ++--- 2 files changed, 33 insertions(+), 44 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 1e8dec6..9199479 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 @@ -153,6 +153,9 @@ object NCCli extends App { case class SplitError(index: Int) extends Exception + case class UnknownCommand(cmd: String) + extends IllegalArgumentException(s"Unknown command ${c("'" + cmd + "'")}, type ${c("'help'")} to get help.") + case class NoLocalServer() extends IllegalStateException(s"Local server not found, use $C'start-server'$RST command to start one.") @@ -1481,7 +1484,7 @@ object NCCli extends App { case None ⇒ err = true - errorUnknownCommand(cmdName) + throw UnknownCommand(cmdName) } } @@ -2646,7 +2649,7 @@ object NCCli extends App { exitStatus = 1 if (msg != null && msg.nonEmpty) - logln(s"${y("ERR:")} ${if (msg.head.isLower) msg.head.toUpper + msg.tail else msg}") + logln(s"${r("X")} ${if (msg.head.isLower) msg.head.toUpper + msg.tail else msg}") } /** @@ -2655,7 +2658,7 @@ object NCCli extends App { */ private def warn(msg: String = ""): Unit = if (msg != null && msg.nonEmpty) - logln(s"${y("WRN:")} ${if (msg.head.isLower) msg.head.toUpper + msg.tail else msg}") + logln(s"${y("!")} ${if (msg.head.isLower) msg.head.toUpper + msg.tail else msg}") /** * @@ -2676,16 +2679,6 @@ object NCCli extends App { } /** - * - */ - private def errorUnknownCommand(cmd: String): Unit = { - val c2 = c(s"'$cmd'") - val h2 = c(s"'help'") - - error(s"Unknown command $c2, type $h2 to get help.") - } - - /** * Prints out the version and copyright title header. */ private def title(): Unit = { @@ -2947,40 +2940,34 @@ object NCCli extends App { @throws[Exception] private def doCommand(args: Seq[String], repl: Boolean): Unit = { if (args.nonEmpty) { - if (args.head.head == '$') { - val head = args.head.tail.trim // Remove '$' from 1st argument. - val tail = args.tail.toList + try + if (args.head.head == '$') { + val head = args.head.tail.trim // Remove '$' from 1st argument. + val tail = args.tail.toList - try execOsCmd(if (head.isEmpty) tail else head :: tail) - catch { - case e: Exception ⇒ error(e.getLocalizedMessage) } - } - else { - // Process 'no-ansi' and 'ansi' commands first. - processAnsi(args, repl) - - // Remove 'no-ansi' and 'ansi' commands from the argument list, if any. - val xargs = args.filter(arg ⇒ arg != NO_ANSI_CMD.name && arg != ANSI_CMD.name) + else { + // Process 'no-ansi' and 'ansi' commands first. + processAnsi(args, repl) - if (xargs.nonEmpty) { - val cmd = xargs.head + // Remove 'no-ansi' and 'ansi' commands from the argument list, if any. + val xargs = args.filter(arg ⇒ arg != NO_ANSI_CMD.name && arg != ANSI_CMD.name) - CMDS.find(_.name == cmd) match { - case Some(cmd) ⇒ - // Reset error code. - exitStatus = 0 + if (xargs.nonEmpty) { + val cmd = xargs.head - try - cmd.body(cmd, processParameters(cmd, xargs.tail), repl) - catch { - case e: Exception ⇒ error(e.getLocalizedMessage) - } + // Reset error code. + exitStatus = 0 - case None ⇒ errorUnknownCommand(cmd) + CMDS.find(_.name == cmd) match { + case Some(cmd) ⇒ cmd.body(cmd, processParameters(cmd, xargs.tail), repl) + case None ⇒ throw UnknownCommand(cmd) + } } } + catch { + case e: Exception ⇒ error(e.getLocalizedMessage) } } } 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 bba6708..0b66262 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 @@ -451,6 +451,7 @@ object NCSqlModelGeneratorImpl { * @param col * @return */ + //noinspection SameParameterValue private def getString(rs: ResultSet, col: String): String = Try(rs.getString(col)).getOrElse("No data") @@ -459,6 +460,7 @@ object NCSqlModelGeneratorImpl { * @param col * @return */ + //noinspection SameParameterValue private def getInt(rs: ResultSet, col: String): Int = Try(rs.getInt(col)).getOrElse(-1) @@ -633,13 +635,13 @@ object NCSqlModelGeneratorImpl { | ${c("--password|-w")} ${g("password")} | Optional database user password. | - | ${c("--model-id|-x")} ${g("id")} + | ${c("--mdlId|-m")} ${g("id")} | Optional generated model ID. By default, the model ID will be 'sql.model.id'. | - | ${c("--model-ver|-v")} ${g("version")} + | ${c("--mdlVer|-v")} ${g("version")} | Optional generated model version. By default, the model version will be '1.0.0-timestamp'. | - | ${c("--model-name|-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")} @@ -773,9 +775,9 @@ object NCSqlModelGeneratorImpl { case "--user" | "-u" ⇒ params.user = v case "--password" | "-w" ⇒ params.password = v case "--schema" | "-s" ⇒ params.schema = v - case "--model-id" | "-x" ⇒ params.modelId = v - case "--model-name" | "-n" ⇒ params.modelName = v - case "--model-ver" | "-v" ⇒ params.modelVer = v + case "--mdlId" | "-m" ⇒ params.modelId = v + case "--mdlName" | "-n" ⇒ params.modelName = v + case "--mdlVer" | "-v" ⇒ params.modelVer = v case "--out" | "-o" ⇒ params.output = v case "--include" | "-i" ⇒ params.inclSpec = v; params.inclPred = mkPredicate(v) case "--exclude" | "-e" ⇒ params.exclSpec = v; params.exclPred = mkPredicate(v)
