mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
readme: document new syntax for synamic variables
This commit is contained in:
26
README.md
26
README.md
@@ -303,7 +303,7 @@ Example of `Taskvars.yml` file:
|
|||||||
```yml
|
```yml
|
||||||
PROJECT_NAME: My Project
|
PROJECT_NAME: My Project
|
||||||
DEV_MODE: production
|
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
|
> NOTE: It's also possible setting a variable globally using `set` attribute
|
||||||
@@ -323,20 +323,34 @@ set-message:
|
|||||||
|
|
||||||
#### Dynamic variables
|
#### Dynamic variables
|
||||||
|
|
||||||
If you prefix a variable with `$`, then the variable is considered a dynamic
|
The below syntax (`sh:` prop in a variable) is considered a dynamic
|
||||||
variable. The value after the $-symbol will be treated as a command and the
|
variable. The value will be treated as a command and the output assigned.
|
||||||
output assigned.
|
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- go build -ldflags="-X main.Version={{.LAST_GIT_COMMIT}}" main.go
|
- go build -ldflags="-X main.Version={{.GIT_COMMIT}}" main.go
|
||||||
vars:
|
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.
|
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
|
### Go's template engine
|
||||||
|
|
||||||
Task parse commands as [Go's template engine][gotemplate] before executing
|
Task parse commands as [Go's template engine][gotemplate] before executing
|
||||||
|
Reference in New Issue
Block a user