This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-346
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-346 by this push:
     new cfd6481  WIP.
cfd6481 is described below

commit cfd6481a660a1024b4fbd5c5f99ff8ed0624bf46
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Wed Jun 30 15:32:02 2021 -0700

    WIP.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 97 ++--------------------
 .../tools/cmdline/NCCliFileNameCompleter.java      |  2 +-
 2 files changed, 6 insertions(+), 93 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 57d3394..9e726c8 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
@@ -2276,6 +2276,8 @@ object NCCli extends NCCliBase {
         val completer: Completer = new Completer {
             private val cmds = CMDS.map(c => (c.name, c.synopsis, c.group))
 
+            private val fsCompleter = new NCCliFileNameCompleter()
+
             /**
              *
              * @param disp
@@ -2289,16 +2291,6 @@ object NCCli extends NCCliBase {
 
             /**
              *
-             * @param paramName
-             * @param path
-             * @param isDir
-             * @return
-             */
-            def mkPathCandidate(paramName: String, path: File, isDir: 
Boolean): Candidate =
-                new Candidate(s"$paramName=${path.getAbsolutePath}", 
path.getName, if (isDir) "Directories:" else "Files:", null, null, null, false)
-
-            /**
-             *
              * @param param
              * @return
              */
@@ -2356,42 +2348,11 @@ object NCCli extends NCCliBase {
                         )
                     }).asJava)
                 }
-                else if (words.size > 1 && isFsPath(words.head, words.last)) {
-                    val param = words.last
-
-                    splitEqParam(param) match {
-                        case Some((paramName, pathValue)) =>
-                            var path = if (pathValue.isEmpty) USR_WORK_DIR 
else replacePathTilda(pathValue).strip()
-
-                            var ok = !new File(path).exists
-
-                            while (ok) {
-                                val pathElms = path.split(PATH_SEP_CH).toSeq
-
-                                if (pathElms.size > 1) {
-                                    path = 
pathElms.dropRight(1).mkString(PATH_SEP_STR)
-
-                                    if (path.endsWith(":"))
-                                        path += PATH_SEP_STR
-
-                                    ok = !new File(path).exists
-                                } else
-                                    ok = false
-                            }
-
-                            val dirs = new File(path).listFiles(new 
io.FileFilter() {
-                                override def accept(file: File): Boolean = 
file.isDirectory && file.canRead
-                            }).toSeq
-                            val files = new File(path).listFiles(new 
io.FileFilter() {
-                                override def accept(file: File): Boolean = 
file.isFile && file.canRead
-                            }).toSeq
-
-                            dirs.foreach(dir => 
candidates.add(mkPathCandidate(paramName, dir, isDir = true)))
-                            files.foreach(file => 
candidates.add(mkPathCandidate(paramName, file, isDir = false)))
-
+                else if (words.size > 1 && isFsPath(words.head, words.last))
+                    splitEqParam(words.last) match {
+                        case Some((_, path)) => 
fsCompleter.fillCandidates(reader, path, candidates)
                         case None => ()
                     }
-                }
                 else {
                     val cmd = words.head
 
@@ -3057,56 +3018,8 @@ object NCCli extends NCCliBase {
         sys.exit(exitStatus)
     }
 
-    private def testBoot(): Unit = {
-        /**
-         *
-         * @param paramName
-         * @param path
-         * @param isDir
-         * @return
-         */
-        def mkPathCandidate(paramName: String, path: File, isDir: Boolean): 
Candidate =
-            new Candidate(s"$paramName=${path.getAbsolutePath}", path.getName, 
if (isDir) "Directories:" else "Files:", null, null, null, false)
-
-        val paramName = "--cp"
-        val pathValue = ""
-
-        var path = if (pathValue.isEmpty) USR_WORK_DIR else 
replacePathTilda(pathValue).strip()
-
-        var ok = !new File(path).exists
-
-        while (ok) {
-            val pathElms = path.split(PATH_SEP_CH).toSeq
-
-            if (pathElms.size > 1) {
-                path = pathElms.dropRight(1).mkString(PATH_SEP_STR)
-
-                if (path.endsWith(":"))
-                    path += PATH_SEP_STR
-
-                ok = !new File(path).exists
-            } else
-                ok = false
-        }
-
-        val dirs = new File(path).listFiles(new io.FileFilter() {
-            override def accept(file: File): Boolean = file.isDirectory && 
file.canRead
-        }).toSeq
-        val files = new File(path).listFiles(new io.FileFilter() {
-            override def accept(file: File): Boolean = file.isFile && 
file.canRead
-        }).toSeq
-
-        val candidates = mutable.ListBuffer.empty[Candidate]
-
-        dirs.foreach(dir => candidates.append(mkPathCandidate(paramName, dir, 
isDir = true)))
-        files.foreach(file => candidates.append(mkPathCandidate(paramName, 
file, isDir = false)))
-
-        println(candidates)
-    }
-
     cleanUpTempFiles()
 
     // Boot up.
     boot(args)
-    //testBoot()
 }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliFileNameCompleter.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliFileNameCompleter.java
index 01c3f09..1f07763 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliFileNameCompleter.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliFileNameCompleter.java
@@ -136,7 +136,7 @@ class NCCliFileNameCompleter
 
     /**
      *
-     * @param useForwardSlash
+     * @param useForwardSlash Terminal configuration property.
      */
     private String getSeparator(boolean useForwardSlash) {
         return useForwardSlash ? "/" : 
getUserDir().getFileSystem().getSeparator();

Reply via email to