Aliases

Aliases within a Run Definition

If you have values that you want to use in multiple places in your run definition, you can define aliases and use yaml anchors.

The keys are arbitrary, but by convention, it's common to have them match the anchor name.

aliases:
  string-example: &string-example 'echo "this is an example of using an alias"'

  multiline-string-example: &multiline-string-example |
    echo "line one"
    echo "line two"

  object-example: &object-example
    ONE: value1
    TWO: value2

  array-example: &array-example
    - key: bg-process-1
      run: while true; do echo "hello from bg process 1"; sleep 1; done
    - key: bg-process-2
      run: while true; do echo "hello from bg process 2"; sleep 1; done

tasks:
  - key: example-using-alias
    run: *string-example

  - key: example-using-multiline-alias
    run: *multiline-string-example

  - key: example-using-object
    run: echo $ONE $TWO
    env: *object-example

  - key: example-using-merge
    run: echo $ONE $TWO $THREE
    env:
      <<: *object-example
      THREE: value3

  - key: example-using-array
    run: sleep 5
    background-processes: *array-example

  - key: example-using-array-flattening
    run: sleep 5
    background-processes:
      - *array-example
      - key: bg-process-3
        run: while true; do echo "hello from bg process 3"; sleep 1; done

Run Command Joining

You can pass an array to run on tasks and Mint will merge the strings together with newlines. This can be helpful for reusing common scripts or commands for setup.

aliases:
  setup-script: &setup-script |
    echo "put your setup commands here"

tasks:
  - key: example
    run:
      - *setup-script
      - echo "put further commands here"

Array Flattening

To make it easier to use aliases when composing definitions, Mint will automatically flatten arrays. This enables you to define an alias for an array of values, while still appending to the array along with using the alias.

The example-using-array-flattening above shows how this works. Ultimately, that example sets background-processes to an array containing three values.