From 3beb8015b972e98930678d0281901222c5aa3360 Mon Sep 17 00:00:00 2001 From: Hendrik Cannoodt Date: Thu, 12 Dec 2024 11:54:39 +0100 Subject: [PATCH 1/5] add `---` parameter to component help messages --- CHANGELOG.md | 2 ++ .../io/viash/runners/ExecutableRunner.scala | 22 +++++++++++++++ .../scala/io/viash/wrapper/BashWrapper.scala | 28 +++++++++++-------- .../io/viash/wrapper/BashWrapperMods.scala | 2 ++ 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 169e744de..458a93a28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ TODO add summary The biggest change is how the exporting of the schema is done, but this has no impact on the user. However, switching to Scala 3 allows for additional features and improvements in the future. +* `--help`: Component `--help` messages will now display what built in `---` options are available (PR #xxx). + ## BUG FIXES * `config build`: Fix a bug where a missing main script would cause a stack trace instead of a proper error message (PR #776). diff --git a/src/main/scala/io/viash/runners/ExecutableRunner.scala b/src/main/scala/io/viash/runners/ExecutableRunner.scala index d72df7907..3861c581b 100644 --- a/src/main/scala/io/viash/runners/ExecutableRunner.scala +++ b/src/main/scala/io/viash/runners/ExecutableRunner.scala @@ -165,6 +165,12 @@ final case class ExecutableRunner( | shift 1 | ;;""".stripMargin + val helpStrings = + s"""Viash built in Engines: + | ---engine=ENGINE_ID + | Specify the engine to use. Options are: ${engines.map(_.id).mkString(", ")}. + | Default: ${engines.head.id}""".stripMargin + val typeSetterStrs = engines.groupBy(_.`type`).map{ case (engineType, engineList) => s""" ${oneOfEngines(engineList)} ; then | VIASH_ENGINE_TYPE='${engineType}'""".stripMargin @@ -179,6 +185,7 @@ final case class ExecutableRunner( BashWrapperMods( preParse = preParse, + helpStrings = List(("Engine", helpStrings)), parsers = parsers, postParse = postParse ) @@ -337,6 +344,20 @@ final case class ExecutableRunner( | shift 1 | ;;""".stripMargin + val helpStrings = + s"""Viash built in Docker: + | ---setup=STRATEGY + | Setup the docker container. Options are: alwaysbuild, alwayscachedbuild, ifneedbebuild, ifneedbecachedbuild, alwayspull, alwayspullelsebuild, alwayspullelsecachedbuild, ifneedbepull, ifneedbepullelsebuild, ifneedbepullelsecachedbuild, push, pushifnotpresent, donothing. + | Default: ifneedbepullelsecachedbuild + | ---dockerfile + | Print the dockerfile to stdout. + | ---docker_run_args=ARG + | Provide runtime arguments to Docker. See the documentation on `docker run` for more information. + | ---docker_image_id + | Print the docker image id to stdout. + | ---debug + | Enter the docker container for debugging purposes.""".stripMargin + val setDockerImageId = engines.map { engine => s"""[[ "$$VIASH_ENGINE_ID" == '${engine.id}' ]]; then | VIASH_DOCKER_IMAGE_ID='${engine.getTargetIdentifier(config).toString()}'""".stripMargin @@ -382,6 +403,7 @@ final case class ExecutableRunner( BashWrapperMods( preParse = preParse, + helpStrings = List(("Docker", helpStrings)), parsers = parsers, postParse = postParse ) diff --git a/src/main/scala/io/viash/wrapper/BashWrapper.scala b/src/main/scala/io/viash/wrapper/BashWrapper.scala index 775532784..a59417376 100644 --- a/src/main/scala/io/viash/wrapper/BashWrapper.scala +++ b/src/main/scala/io/viash/wrapper/BashWrapper.scala @@ -102,6 +102,19 @@ object BashWrapper { } } + def generateHelp(helpSections: List[(String, String)]): String = { + val sections = helpSections.sortBy(_._1).map(_._2) + val helpStr = joinSections(sections).split("\n") + .map(h => Bash.escapeString(h, quote = true)) + .mkString(" echo \"", "\"\n echo \"", "\"") + val functionStr = + s"""# ViashHelp: Display helpful explanation about this executable + |function ViashHelp { + |$helpStr + |}""".stripMargin + spaceCode(functionStr) + } + /** * Joins multiple strings such that there are two spaces between them. * @@ -284,6 +297,7 @@ object BashWrapper { |VIASH_META_TEMP_DIR="$$VIASH_TEMP" | |${spaceCode(allMods.preParse)} + |${generateHelp(allMods.helpStrings)} |# initialise array |VIASH_POSITIONAL_ARGS='' | @@ -336,18 +350,8 @@ object BashWrapper { private def generateHelp(config: Config) = { - val help = Helper.generateHelp(config) - val helpStr = help - .map(h => Bash.escapeString(h, quote = true)) - .mkString(" echo \"", "\"\n echo \"", "\"") - - val preParse = - s"""# ViashHelp: Display helpful explanation about this executable - |function ViashHelp { - |$helpStr - |}""".stripMargin - - BashWrapperMods(preParse = preParse) + val help = Helper.generateHelp(config).mkString("\n") + BashWrapperMods(helpStrings = List(("", help))) } private def generateParsers(params: List[Argument[_]]) = { diff --git a/src/main/scala/io/viash/wrapper/BashWrapperMods.scala b/src/main/scala/io/viash/wrapper/BashWrapperMods.scala index 6d537eea9..37b4e4dcb 100644 --- a/src/main/scala/io/viash/wrapper/BashWrapperMods.scala +++ b/src/main/scala/io/viash/wrapper/BashWrapperMods.scala @@ -21,6 +21,7 @@ import io.viash.config.arguments.Argument case class BashWrapperMods( preParse: String = "", + helpStrings: List[(String, String)] = Nil, parsers: String = "", postParse: String = "", preRun: String = "", @@ -31,6 +32,7 @@ case class BashWrapperMods( def `++`(other: BashWrapperMods): BashWrapperMods = { BashWrapperMods( preParse = BashWrapper.joinSections(List(preParse, other.preParse)), + helpStrings = helpStrings ++ other.helpStrings, parsers = BashWrapper.joinSections(List(parsers, other.parsers), middle = "\n"), postParse = BashWrapper.joinSections(List(postParse, other.postParse)), preRun = BashWrapper.joinSections(List(preRun, other.preRun)), From d5e451b687d67b2600f771d5d3b848797fa85cc3 Mon Sep 17 00:00:00 2001 From: Hendrik Cannoodt Date: Thu, 12 Dec 2024 11:58:04 +0100 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 458a93a28..efa479144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ TODO add summary The biggest change is how the exporting of the schema is done, but this has no impact on the user. However, switching to Scala 3 allows for additional features and improvements in the future. -* `--help`: Component `--help` messages will now display what built in `---` options are available (PR #xxx). +* `--help`: Component `--help` messages will now display what built in `---` options are available (PR #784). ## BUG FIXES From 6ca2bed33786ba8f5e9756316e8221545416ee82 Mon Sep 17 00:00:00 2001 From: Hendrik Cannoodt Date: Thu, 12 Dec 2024 13:38:35 +0100 Subject: [PATCH 3/5] fix nextflow help testbench --- .../scala/io/viash/runners/nextflow/Vdsl3ModuleTest.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/scala/io/viash/runners/nextflow/Vdsl3ModuleTest.scala b/src/test/scala/io/viash/runners/nextflow/Vdsl3ModuleTest.scala index c048348c7..e8188119a 100644 --- a/src/test/scala/io/viash/runners/nextflow/Vdsl3ModuleTest.scala +++ b/src/test/scala/io/viash/runners/nextflow/Vdsl3ModuleTest.scala @@ -105,11 +105,16 @@ class Vdsl3ModuleTest extends AnyFunSuite with BeforeAndAfterAll { "run", workflowsPath + "/pipeline3/config.vsh.yaml", "--", "--help" ) + + // explicitly remove triple dash parameters + // these make sense when running from command line, not when running in nextflow + val correctedTestOutput = testOutput.stdout.replaceAll("""\n\nViash built in .*(\n\s{4}---.*\n(\s{8}.*)+)*""", "") + assert(testOutput.exitCode == Some(0)) // check if they are the same - assert(correctedStdOut2 == testOutput.stdout) + assert(correctedStdOut2 == correctedTestOutput) } override def afterAll(): Unit = { From 019eb82de0aa5967acc1839516ee8996628d5031 Mon Sep 17 00:00:00 2001 From: Hendrik Cannoodt Date: Fri, 13 Dec 2024 11:39:34 +0100 Subject: [PATCH 4/5] Add help entries for ---cpus and ---memory --- src/main/scala/io/viash/wrapper/BashWrapper.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/scala/io/viash/wrapper/BashWrapper.scala b/src/main/scala/io/viash/wrapper/BashWrapper.scala index a59417376..ff0a50778 100644 --- a/src/main/scala/io/viash/wrapper/BashWrapper.scala +++ b/src/main/scala/io/viash/wrapper/BashWrapper.scala @@ -727,6 +727,15 @@ object BashWrapper { private def generateComputationalRequirements(config: Config) = { + + val helpStrings = + """Viash built in Computational Requirements: + | ---cpus=INT + | Number of CPUs to use + | ---memory=STRING + | Amount of memory to use + |""".stripMargin + val compArgs = List( ("---cpus", "VIASH_META_CPUS", config.requirements.cpus.map(_.toString)), ("---memory", "VIASH_META_MEMORY", config.requirements.memoryAsBytes.map(_.toString + "b")) @@ -805,6 +814,7 @@ object BashWrapper { // return output BashWrapperMods( + helpStrings = List(("Computational Requirements", helpStrings)), parsers = parsers, postParse = BashWrapper.joinSections(List(defaultsStrs, memoryCalculations)) ) From 73de5cafe5932440060c8e2c50c1ab9c2c4b7721 Mon Sep 17 00:00:00 2001 From: Hendrik Cannoodt Date: Mon, 16 Dec 2024 13:16:41 +0100 Subject: [PATCH 5/5] Update src/main/scala/io/viash/wrapper/BashWrapper.scala Co-authored-by: Robrecht Cannoodt --- src/main/scala/io/viash/wrapper/BashWrapper.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/io/viash/wrapper/BashWrapper.scala b/src/main/scala/io/viash/wrapper/BashWrapper.scala index ff0a50778..2d9f4813c 100644 --- a/src/main/scala/io/viash/wrapper/BashWrapper.scala +++ b/src/main/scala/io/viash/wrapper/BashWrapper.scala @@ -733,7 +733,7 @@ object BashWrapper { | ---cpus=INT | Number of CPUs to use | ---memory=STRING - | Amount of memory to use + | Amount of memory to use. Examples: 4GB, 3MiB. |""".stripMargin val compArgs = List(