mirror of
https://github.com/go-task/task.git
synced 2025-07-17 01:43:07 +02:00
improve README documentation
This commit is contained in:
76
README.md
76
README.md
@ -148,6 +148,9 @@ css:
|
|||||||
- npm run buildcss
|
- npm run buildcss
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If there are more than one dependency, they always run in parallel for better
|
||||||
|
performance.
|
||||||
|
|
||||||
Each task can only be run once. If it is included from another dependend task causing
|
Each task can only be run once. If it is included from another dependend task causing
|
||||||
a cyclomatic dependency, execution will be stopped.
|
a cyclomatic dependency, execution will be stopped.
|
||||||
|
|
||||||
@ -268,55 +271,52 @@ up-to-date.
|
|||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
```yml
|
When doing interpolation of variables, Task will look for the below.
|
||||||
build:
|
They are listed below in order of importance (e.g. most important first):
|
||||||
deps: [setvar]
|
|
||||||
cmds:
|
|
||||||
- echo "{{.PREFIX}} {{.THEVAR}}"
|
|
||||||
vars:
|
|
||||||
PREFIX: "Path:"
|
|
||||||
|
|
||||||
setvar:
|
- Variables given while calling a task from another.
|
||||||
cmds:
|
(See [Calling another task](#calling-another-task) above)
|
||||||
- echo "{{.PATH}}"
|
- Environment variables
|
||||||
set: THEVAR
|
- Variables available in the `Taskvars.yml` file
|
||||||
|
- Variables declared locally in the task
|
||||||
|
|
||||||
|
Example of overriding with environment variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ TASK_VARIABLE=a-value task do-something
|
||||||
```
|
```
|
||||||
|
|
||||||
The above sample saves the path into a new variable which is then again echoed.
|
Example of `Taskvars.yml` file:
|
||||||
|
|
||||||
You can use environment variables, task level variables and a file called
|
```yml
|
||||||
`Taskvars.yml` as source of variables.
|
PROJECT_NAME: My Project
|
||||||
|
DEV_MODE: production
|
||||||
|
GIT_COMMIT: $git log -n 1 --format=%h
|
||||||
|
```
|
||||||
|
|
||||||
They are evaluated in the following order:
|
Example of locally declared vars:
|
||||||
|
|
||||||
Task local variables are overwritten by variables found in `Taskvars` file.
|
```yml
|
||||||
Variables found in `Taskvars` file are overwritten with variables from the
|
print-var:
|
||||||
environment. The output of the last command is stored in the environment. So
|
cmds:
|
||||||
you can do something like this:
|
echo "{{.VAR}}"
|
||||||
|
vars:
|
||||||
|
VAR: Hello!
|
||||||
|
```
|
||||||
|
|
||||||
|
> NOTE: It's also possible setting a variable globally using `set` attribute
|
||||||
|
in task, but this is deprecated:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
build:
|
build:
|
||||||
deps: [setvar]
|
deps: [set-message]
|
||||||
cmds:
|
cmds:
|
||||||
- echo "{{.PREFIX}} '{{.THEVAR}}'"
|
- echo "Message: {{.MESSAGE}}"
|
||||||
vars:
|
|
||||||
PREFIX: "Result: "
|
|
||||||
|
|
||||||
setvar:
|
set-message:
|
||||||
cmds:
|
cmds:
|
||||||
- echo -n "a"
|
- echo "This is an important message"
|
||||||
- echo -n "{{.THEVAR}}b"
|
set: MESSAGE
|
||||||
- echo -n "{{.THEVAR}}c"
|
|
||||||
set: THEVAR
|
|
||||||
```
|
|
||||||
|
|
||||||
The result of a run of build would be:
|
|
||||||
|
|
||||||
```
|
|
||||||
a
|
|
||||||
ab
|
|
||||||
abc
|
|
||||||
Result: 'abc'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Dynamic variables
|
#### Dynamic variables
|
||||||
@ -333,6 +333,8 @@ build:
|
|||||||
LAST_GIT_COMMIT: $git log -n 1 --format=%h
|
LAST_GIT_COMMIT: $git log -n 1 --format=%h
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This works for all types of variables.
|
||||||
|
|
||||||
### 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