1
0
mirror of https://github.com/go-task/task.git synced 2025-01-26 05:27:15 +02:00

readme: document new syntax for synamic variables

This commit is contained in:
Andrey Nering 2017-07-15 15:37:24 -03:00
parent e8e914b11c
commit 2607866c49

View File

@ -303,7 +303,7 @@ Example of `Taskvars.yml` file:
```yml
PROJECT_NAME: My Project
DEV_MODE: production
GIT_COMMIT: $git log -n 1 --format=%h
GIT_COMMIT: {sh: git log -n 1 --format=%h}
```
> NOTE: It's also possible setting a variable globally using `set` attribute
@ -323,20 +323,34 @@ set-message:
#### Dynamic variables
If you prefix a variable with `$`, then the variable is considered a dynamic
variable. The value after the $-symbol will be treated as a command and the
output assigned.
The below syntax (`sh:` prop in a variable) is considered a dynamic
variable. The value will be treated as a command and the output assigned.
```yml
build:
cmds:
- go build -ldflags="-X main.Version={{.LAST_GIT_COMMIT}}" main.go
- go build -ldflags="-X main.Version={{.GIT_COMMIT}}" main.go
vars:
LAST_GIT_COMMIT: $git log -n 1 --format=%h
GIT_COMMIT:
sh: git log -n 1 --format=%h
```
This works for all types of variables.
> It's also possible to prefix the variable with `$` to have a dynamic
variable, but this is now considered deprecated:
```yml
# Taskvars.yml
# recommended
GIT_COMMIT:
sh: git log -n 1 --format=%h
# deprecated
GIT_COMMIT: $git log -n 1 --format=%h
```
### Go's template engine
Task parse commands as [Go's template engine][gotemplate] before executing