mumoshu / variant2

Turn your bash scripts into a modern, single-executable CLI app today
MIT License
141 stars 11 forks source link

Add support for variables to use variables in the value #15

Closed johncblandii closed 4 years ago

johncblandii commented 4 years ago

This specific use-case is to help DRY up code and make it a bit more readable inside of the job.

job "myjob" {
  option "value" {
    default     = coalesce(list(""))
    description = "args to pass to subcommand"
    type        = string
  }

  variable "valuesplit" {
    type = list(string)
    value = split(".", opt.value)
  }

  variable "cmd" {
    type = string
    value = var.valuesplit[0]
  }

  variable "project" {
    type = string
    value = var.valuesplit[1]
  }

  exec {
    command = "echo"
    args    = "run ${var.cmd} inside directory ${var.project}"
  }
}

This allows var.cmd to be used to in the exec vs:

    args    = "run ${var.valuesplit[0]} inside directory ${var.valuesplit[1]}"