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/10/23 02:31:11 UTC
[incubator-nlpcraft] branch master updated: Fix for NLPCRAFT-162.
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
The following commit(s) were added to refs/heads/master by this push:
new 07866ec Fix for NLPCRAFT-162.
07866ec is described below
commit 07866eca0026547b6755914364f714524a5fd18f
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Thu Oct 22 19:30:59 2020 -0700
Fix for NLPCRAFT-162.
---
.../nlpcraft/model/tools/cmdline/NCCli.scala | 25 ++++++++++++++++------
1 file changed, 19 insertions(+), 6 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 dd56754..7b21809 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
@@ -58,6 +58,7 @@ import scala.compat.java8.OptionConverters._
import scala.collection.JavaConverters._
import scala.compat.Platform.currentTime
import scala.util.Try
+import scala.util.control.Breaks.{break, breakable}
import scala.util.control.Exception.ignoring
/**
@@ -1413,18 +1414,28 @@ object NCCli extends App {
case None ⇒ 20 // Default.
}
+ if (lines <= 0)
+ throw InvalidParameter(cmd, "lines")
+
loadServerBeacon() match {
case Some(beacon) ⇒
try
managed(new ReversedLinesFileReader(new File(beacon.logPath), StandardCharsets.UTF_8)) acquireAndGet { in ⇒
var tail = List.empty[String]
- for (_ ← 0 to lines)
- tail ::= in.readLine()
+ breakable {
+ for (_ ← 0 until lines)
+ in.readLine() match {
+ case null ⇒ break
+ case line ⇒ tail ::= line
+ }
+ }
+
+ val cnt = tail.size
- logln(bb(w(s"+----< ${K}Last $lines server log lines $W>---")))
+ logln(bb(w(s"+----< ${K}Last $cnt server log lines $W>---")))
tail.foreach(line ⇒ logln(s"${bb(w("| "))} $line"))
- logln(bb(w(s"+----< ${K}Last $lines server log lines $W>---")))
+ logln(bb(w(s"+----< ${K}Last $cnt server log lines $W>---")))
}
catch {
case e: Exception ⇒ error(s"Failed to read log file: ${e.getLocalizedMessage}")
@@ -1903,7 +1914,9 @@ object NCCli extends App {
* @param repl Whether or not executing from REPL.
*/
private def cmdNano(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
- if (args.size > 1)
+ if (args.isEmpty)
+ throw NotEnoughArguments(cmd)
+ else if (args.size > 1)
throw TooManyArguments(cmd)
Commands.nano(term,
@@ -1955,7 +1968,7 @@ object NCCli extends App {
private def cmdLess(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
if (args.isEmpty)
throw NotEnoughArguments(cmd)
- else if (args.size > 1)
+ else if (args.size > 1)
throw TooManyArguments(cmd)
Commands.less(term,