File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package io.viash.config.arguments
1919
2020import io .circe .Json
2121import io .viash .helpers .data_structures ._
22+ import io .viash .helpers .Bash
2223import io .viash .schemas ._
2324import java .nio .file .Paths
2425
@@ -82,12 +83,8 @@ abstract class Argument[Type] {
8283 /** Common parameter name for this argument */
8384 val par : String = dest + " _" + plainName
8485
85- /** Parameter name in bash scripts
86- * For backwards compatibility, meta variables still use uppercase plainName.
87- * Par and dep variables use lowercase plainName for so variables with similar names do not clash.
88- * Examples: VIASH_META_NAME, VIASH_PAR_input, VIASH_DEP_my_dependency
89- */
90- val VIASH_PAR : String = " VIASH_" + dest.toUpperCase + " _" + (if (dest == " meta" ) plainName.toUpperCase() else plainName)
86+ /** Parameter name in bash scripts - see Bash.viashVarName for naming convention */
87+ val VIASH_PAR : String = Bash .viashVarName(dest, plainName)
9188
9289 def copyArg (
9390 `type` : String = this .`type`,
Original file line number Diff line number Diff line change @@ -112,8 +112,8 @@ case class Dependency(
112112 // So after that step we must always use the righthand object. This makes that much easier.
113113 def workRepository : Option [Repository ] = repository.toOption
114114
115- // Name in BashWrapper
116- def VIASH_DEP : String = s " VIASH_DEP_ ${alias.getOrElse(name).replace( " / " , " _ " ).toUpperCase()} "
115+ // Name in BashWrapper - see Bash.viashVarName for naming convention
116+ def VIASH_DEP : String = io.viash.helpers. Bash .viashVarName( " dep " , alias.getOrElse(name))
117117 // Name to be used in scripts
118118 def scriptName : String = alias.getOrElse(name).replace(" /" , " _" )
119119 // Part of the folder structure where dependencies should be written to, contains the repository & dependency name
Original file line number Diff line number Diff line change @@ -76,4 +76,21 @@ object Bash {
7676 .replaceWith(" \\\\\\ $VIASH_" , " \\ $VIASH_" , allowUnescape)
7777 .replaceWith(" \\\\\\ $\\ {VIASH_" , " \\ ${VIASH_" , allowUnescape)
7878 }
79- }
79+ /**
80+ * Generate a VIASH variable name for use in bash scripts.
81+ *
82+ * For backwards compatibility, meta variables use uppercase names.
83+ * Par and dep variables use lowercase names so variables with similar names
84+ * (e.g. "--input" and "--INPUT") do not clash.
85+ *
86+ * Examples: VIASH_META_NAME, VIASH_PAR_input, VIASH_DEP_my_dependency
87+ *
88+ * @param dest The destination type: "par", "meta", or "dep"
89+ * @param name The variable name (may contain slashes which are replaced with underscores)
90+ * @return The formatted VIASH variable name
91+ */
92+ def viashVarName (dest : String , name : String ): String = {
93+ val sanitizedName = name.replace(" /" , " _" )
94+ val formattedName = if (dest == " meta" ) sanitizedName.toUpperCase() else sanitizedName
95+ s " VIASH_ ${dest.toUpperCase()}_ $formattedName"
96+ }}
You can’t perform that action at this time.
0 commit comments