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 bbcc7e0 WIP.
bbcc7e0 is described below
commit bbcc7e00b5a55925662bb43bae76040199e4ee70
Author: Aaron Radzinski <[email protected]>
AuthorDate: Wed Jun 30 10:20:32 2021 -0700
WIP.
---
.../org/apache/nlpcraft/common/util/NCUtils.scala | 9 +++
.../nlpcraft/model/tools/cmdline/NCCli.scala | 89 ++++++++++++++++++----
.../nlpcraft/model/tools/cmdline/NCCliBase.scala | 4 +-
3 files changed, 84 insertions(+), 18 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index 20f90f6..ef20c34 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -152,6 +152,15 @@ object NCUtils extends LazyLogging {
def now(): Long = System.currentTimeMillis()
/**
+ *
+ * @param v
+ * @param dflt
+ * @tparam T
+ * @return
+ */
+ def notNull[T <: AnyRef](v: T, dflt: T): T = if (v == null) dflt else v
+
+ /**
* Strips ANSI escape sequences from the given string.
*
* @param s
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 17a1f3b..57d3394 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
@@ -2290,20 +2290,19 @@ object NCCli extends NCCliBase {
/**
*
* @param paramName
- * @param absPath
- * @param name
+ * @param path
* @param isDir
* @return
*/
- private def mkPathCandidate(paramName: String, absPath: String,
name: String, isDir: Boolean): Candidate =
- new Candidate(s"$paramName=$absPath", name, if (isDir)
"Directory" else "File", null, null, null, false)
+ 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
*/
- private def splitEqParam(param: String): Option[(String/*Name*/,
String/*Value*/)] = {
+ def splitEqParam(param: String): Option[(String/*Name*/,
String/*Value*/)] = {
val eqIdx = param.indexOf('=')
if (eqIdx != -1) {
@@ -2360,25 +2359,35 @@ object NCCli extends NCCliBase {
else if (words.size > 1 && isFsPath(words.head, words.last)) {
val param = words.last
- // At this point we know that command and parameter are
valid.
splitEqParam(param) match {
case Some((paramName, pathValue)) =>
- val path = replacePathTilda(pathValue).strip()
+ var path = if (pathValue.isEmpty) USR_WORK_DIR
else replacePathTilda(pathValue).strip()
- var p = if (path.isEmpty) USR_WORK_DIR else path
+ var ok = !new File(path).exists
- while (!new File(p).exists)
- p =
p.split(PATH_SEP_CH).toSeq.dropRight(1).mkString(PATH_SEP_STR)
+ while (ok) {
+ val pathElms = path.split(PATH_SEP_CH).toSeq
- val dirs = new File(p).listFiles(new
io.FileFilter() {
- override def accept(file: File): Boolean =
file.isDirectory
+ 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(p).listFiles(new
io.FileFilter() {
- override def accept(file: File): Boolean =
file.isFile
+ 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, p, dir.getName, isDir = true)))
- files.foreach(file =>
candidates.add(mkPathCandidate(paramName, p, file.getName, isDir = false)))
+ dirs.foreach(dir =>
candidates.add(mkPathCandidate(paramName, dir, isDir = true)))
+ files.foreach(file =>
candidates.add(mkPathCandidate(paramName, file, isDir = false)))
case None => ()
}
@@ -3048,8 +3057,56 @@ 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/NCCliBase.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala
index 1ef181b..1367e96 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliBase.scala
@@ -83,8 +83,8 @@ class NCCliBase extends App {
final val PATH_SEP_CH = File.separatorChar
final val PATH_SEP_STR = File.separator
final val JAVA = U.sysEnv("NLPCRAFT_CLI_JAVA").getOrElse(new
File(SystemUtils.getJavaHome, s"bin/java${if (SystemUtils.IS_OS_UNIX) "" else
".exe"}").getAbsolutePath)
- final val USR_WORK_DIR = SystemUtils.USER_DIR
- final val USR_HOME_DIR = SystemUtils.USER_HOME
+ final val USR_WORK_DIR = U.notNull(SystemUtils.USER_DIR, "")
+ final val USR_HOME_DIR = U.notNull(SystemUtils.USER_HOME, "")
final val INSTALL_HOME =
U.sysEnv("NLPCRAFT_CLI_INSTALL_HOME").getOrElse(USR_WORK_DIR)
final val JAVA_CP =
U.sysEnv("NLPCRAFT_CLI_CP").getOrElse(ManagementFactory.getRuntimeMXBean.getClassPath)
final val SCRIPT_NAME =
U.sysEnv("NLPCRAFT_CLI_SCRIPT").getOrElse(s"nlpcraft.${if
(SystemUtils.IS_OS_UNIX) "sh" else "cmd"}")