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:
parent
e8e914b11c
commit
2607866c49
26
README.md
26
README.md
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user