Variable in manifest
Use variables in manifest.mf file
The two common use cases of integrating commands in command launcher are:
- Reference files that are located in the package itself
- 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 Name | Variable Description |
---|---|
PackageDir | The absolute path of the package |
Root | Same as “PackageDir” variable |
Cache | Same as “PackageDir” variable |
Os | The OS, “windows”, “linux”, and “darwin” |
Arch | The system architecture: “arm64”, “amd64” |
Binary | The binary file name of the command launcher |
Extension | The system-aware binary extension, "" for linux, “.exe” for windows |
ScriptExtension | The 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.