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 89c9f7f Update NCCli.scala
89c9f7f is described below
commit 89c9f7f19910dce2db7a9b41d545ac22c333ad1c
Author: Aaron Radzinski <[email protected]>
AuthorDate: Fri Oct 2 23:50:52 2020 -0700
Update NCCli.scala
---
.../nlpcraft/model/tools/cmdline/NCCli.scala | 35 ++++++++++------------
1 file changed, 15 insertions(+), 20 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 337498c..1a8442b 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
@@ -878,6 +878,17 @@ object NCCli extends App {
val completer = new Completer {
private val cmds = CMDS.map(c ⇒ c.name → c.synopsis)
+ /**
+ *
+ * @param id
+ * @param disp
+ * @param desc
+ * @param completed
+ * @return
+ */
+ private def mkCandidate(id: String, disp: String, desc: String,
completed: Boolean): Candidate =
+ new Candidate(id, disp, null, desc, null, null, completed)
+
override def complete(reader: LineReader, line: ParsedLine,
candidates: util.List[Candidate]): Unit = {
val words = line.words().asScala
@@ -886,37 +897,21 @@ object NCCli extends App {
val name = n._1
val desc = n._2.substring(0, n._2.length - 1) //
Remove last '.'.
- new Candidate(
- name,
- name,
- null,
- desc,
- null,
- null,
- true
- )
+ mkCandidate(name, name, desc, completed = true)
}).asJava)
else {
val cmd = words.head
candidates.addAll(CMDS.find(_.name == cmd) match {
- case Some(c) ⇒ {
+ case Some(c) ⇒
c.params.flatMap(param ⇒ {
val hasVal = param.value.isDefined
val names =
param.names.filter(_.startsWith("--")) // Skip shorthands from auto-completion.
- names.map(name ⇒ new Candidate(
- if (hasVal) name + "=" else name,
- name,
- null,
- null,
- null,
- null,
- !hasVal
- ))
+ names.map(name ⇒ mkCandidate(if (hasVal) name
+ "=" else name, name,null, !hasVal))
})
.asJava
- }
+
case None ⇒ Seq.empty[Candidate].asJava
})
}