Skip to content

Commit 2221898

Browse files
committed
fix formatting
1 parent 28f72cc commit 2221898

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/main/scala/io/viash/config/arguments/Argument.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package io.viash.config.arguments
1919

2020
import io.circe.Json
2121
import io.viash.helpers.data_structures._
22+
import io.viash.helpers.Bash
2223
import io.viash.schemas._
2324
import 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`,

src/main/scala/io/viash/config/dependencies/Dependency.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

src/main/scala/io/viash/helpers/Bash.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
}}

0 commit comments

Comments
 (0)