viash config inject

Inject a Viash header into the main script of a Viash component.

Usage:

viash config inject config.vsh.yaml

Arguments

–config

A Viash config file (example: config.vsh.yaml). This argument can also be a script with the config as a header.

-c, --config_mod

Modify a viash config at runtime using a custom DSL.

-p, --platform

Specifies which platform amongst those specified in the viash config to use. If this is not provided, the first platform will be used. If no platforms are defined in the viash config, the native platform will be used. In addition, the path to a platform yaml file can also be specified.

-h, --help

Show help message

Trailing arguments

config

A viash config file (example: config.vsh.yaml). This argument can also be a script with the config as a header.

Examples

Inject a Viash config into a bash scipt

The config inject command injects a Viash header into the first script found in the resources list. This includes all arguments with defaults set up along with meta variables.
Let’s take this config.vsh.yaml file used in the Creating a Bash Component guide for example:

functionality:
  name: hello_world
  description: A very simple 'Hello world' component.
  arguments:
  - type: string
    name: input
    multiple: true
    multiple_sep: " "
  - type: string
    name: --greeter
    default: "Hello world!"
  resources:
  - type: bash_script
    path: script.sh
  tests:
  - type: bash_script
    path: test.sh
platforms:
  - type: native
  - type: docker
    image: bash:4.0
  - type: docker
    id: alpine
    image: alpine
    setup:
      - type: apk
        packages: [ bash ]

Its script has a single line to print out greeter, followed by all items in input:

echo $par_greeter $par_input

Now execute the config inject command on the config file like this:

viash config inject config.vsh.yaml

If you now take a look at the bash script, a header has been added to the top:

## VIASH START
# The following code has been auto-generated by Viash.
par_input='value'
par_greeter='Hello world!'
meta_functionality_name='hello_world'
meta_resources_dir='/tmp/viash_inject_hello_world8911697245196241485'
resources_dir="/tmp/viash_inject_hello_world8911697245196241485"

## VIASH END

echo $par_greeter $par_input

The variables in this header can be used as a useful starting point to test and debug your script. Their values are based on the default and example values of arguments. Running this script by itself now will give this output:

Hello world! value

When running the config as a Viash component, the generated header will automatically be overwritten, so you can safely leave the Viash header in your scripts.

Override a config with config mods

You can modify the injected config by using a config mod to override the config file.

viash config inject config.vsh.yaml \
-c '.platforms[.type == "docker"].setup_strategy := "pull"' \
-c '.platforms[.type == "docker"].image := "bash:latest"'

See also