Variable in manifest

Use variables in manifest.mf file

The two common use cases of integrating commands in command launcher are:

  1. Reference files that are located in the package itself
  2. Provide system/architecture-aware commands, for example, .sh script for linux, and .bat script for windows

To cover these use cases, in certain fields of the manifest file, predefined variables can used in the field values.

Available Variables

Variable NameVariable Description
PackageDirThe absolute path of the package
RootSame as “PackageDir” variable
CacheSame as “PackageDir” variable
OsThe OS, “windows”, “linux”, and “darwin”
ArchThe system architecture: “arm64”, “amd64”
BinaryThe binary file name of the command launcher
ExtensionThe system-aware binary extension, "" for linux, “.exe” for windows
ScriptExtensionThe system-aware scritp extension, “.sh” for linux, “.bat” for windows

Fields that accepts variables

The command fields: executable, args, and validArgsCmd

How to use these variables

You can reference them in form of {{.Variable}}. For example:

"cmds": [
  {
    "name": "variable-demo",
    "type": "executable",
    "executable": "{{.PackageDir}}/bin/script{{.ScripteExtension}}",
  }
]

The executable on linux will be a script called script.sh located in the bin folder of the package. On windows, the executable will be a script called script.bat.

If Else

One common scenario is to have different path or file name according to different OS. You can use condition (if-else) in the fields that accept variables. For example:

"cmds": [
  {
    "name": "variable-demo",
    "type": "executable",
    "executable": "{{.PackageDir}}/bin/script{{if eq .Os \"windows\"}}.ps1{{else}}.sh{{end}}",
  }
]

The executable on linux will be a script called script.sh located in the bin folder of the package. On windows, the executable will be a script called script.ps1.

Advanced usage of variables

See golang text/template for advanced usage.