2019-10-27 22:28:12 +02:00
|
|
|
# Styleguide
|
|
|
|
|
|
|
|
This is the official Task styleguide for `Taskfile.yml` files. This guide
|
|
|
|
contains some basic instructions to keep your Taskfile clean and familiar to
|
|
|
|
other users.
|
|
|
|
|
|
|
|
This contains general guidelines, but don't necessarely need to be strictly
|
|
|
|
followed. Feel free to disagree and proceed differently in some point if you
|
|
|
|
need or want to. Also, feel free to open issues or pull requests with
|
|
|
|
improvements to this guide.
|
|
|
|
|
|
|
|
## Use `Taskfile.yml` and not `taskfile.yml`
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# bad
|
|
|
|
taskfile.yml
|
|
|
|
|
|
|
|
|
|
|
|
# good
|
|
|
|
Taskfile.yml
|
|
|
|
```
|
|
|
|
|
2019-11-13 13:34:13 +02:00
|
|
|
This is important especially for Linux users. Windows and macOS have case
|
2019-10-27 22:28:12 +02:00
|
|
|
insensitive filesystems, so `taskfile.yml` will end up working, even that not
|
|
|
|
officially supported. On Linux, only `Taskfile.yml` will work, though.
|
|
|
|
|
|
|
|
## Use the correct order of keywords
|
|
|
|
|
|
|
|
- `version:`
|
|
|
|
- `includes:`
|
2019-12-08 02:44:09 +02:00
|
|
|
- Configuration ones, like `output:`, `expansions:` or `silent:`
|
2019-10-27 22:28:12 +02:00
|
|
|
- `vars:`
|
|
|
|
- `env:`
|
|
|
|
- `tasks:`
|
|
|
|
|
|
|
|
## Use 2 spaces for indentation
|
|
|
|
|
|
|
|
This is the most common convention for YAML files, and Task follows it.
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# bad
|
|
|
|
tasks:
|
|
|
|
foo:
|
|
|
|
cmds:
|
|
|
|
- echo 'foo'
|
|
|
|
|
|
|
|
|
|
|
|
# good
|
|
|
|
tasks:
|
|
|
|
foo:
|
|
|
|
cmds:
|
|
|
|
- echo 'foo'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Separate with spaces the mains sections
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# bad
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
includes:
|
|
|
|
docker: ./docker/Taskfile.yml
|
|
|
|
output: prefixed
|
|
|
|
expansions: 3
|
|
|
|
vars:
|
|
|
|
FOO: bar
|
|
|
|
env:
|
|
|
|
BAR: baz
|
|
|
|
tasks:
|
|
|
|
# ...
|
|
|
|
|
|
|
|
|
|
|
|
# good
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
includes:
|
|
|
|
docker: ./docker/Taskfile.yml
|
|
|
|
|
|
|
|
output: prefixed
|
|
|
|
expansions: 3
|
|
|
|
|
|
|
|
vars:
|
|
|
|
FOO: bar
|
|
|
|
|
|
|
|
env:
|
|
|
|
BAR: baz
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
## Add spaces between tasks
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# bad
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
foo:
|
|
|
|
cmds:
|
|
|
|
- echo 'foo'
|
|
|
|
bar:
|
|
|
|
cmds:
|
|
|
|
- echo 'bar'
|
|
|
|
baz:
|
|
|
|
cmds:
|
|
|
|
- echo 'baz'
|
|
|
|
|
|
|
|
|
|
|
|
# good
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
foo:
|
|
|
|
cmds:
|
|
|
|
- echo 'foo'
|
|
|
|
|
|
|
|
bar:
|
|
|
|
cmds:
|
|
|
|
- echo 'bar'
|
|
|
|
|
|
|
|
baz:
|
|
|
|
cmds:
|
|
|
|
- echo 'baz'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Use upper-case variable names
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# bad
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
vars:
|
|
|
|
binary_name: myapp
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
build:
|
|
|
|
cmds:
|
|
|
|
- go build -o {{.binary_name}} .
|
|
|
|
|
|
|
|
|
|
|
|
# good
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
vars:
|
|
|
|
BINARY_NAME: myapp
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
build:
|
|
|
|
cmds:
|
|
|
|
- go build -o {{.BINARY_NAME}} .
|
|
|
|
```
|
|
|
|
|
|
|
|
## Don't wrap vars in spaces when templating
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# bad
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
greet:
|
|
|
|
cmds:
|
|
|
|
- echo '{{ .MESSAGE }}'
|
|
|
|
|
|
|
|
|
|
|
|
# good
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
greet:
|
|
|
|
cmds:
|
|
|
|
- echo '{{.MESSAGE}}'
|
|
|
|
```
|
|
|
|
|
|
|
|
This convention is also used by most people for any Go templating.
|
|
|
|
|
|
|
|
## Separate task name words with a dash
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# bad
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
do_something_fancy:
|
|
|
|
cmds:
|
|
|
|
- echo 'Do something'
|
|
|
|
|
|
|
|
|
|
|
|
# good
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
do-something-fancy:
|
|
|
|
cmds:
|
|
|
|
- echo 'Do something'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Use colon for task namespacing
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# good
|
2020-08-17 02:33:26 +02:00
|
|
|
version: '3'
|
2019-10-27 22:28:12 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
docker:build:
|
|
|
|
cmds:
|
|
|
|
- docker ...
|
|
|
|
|
|
|
|
docker:run:
|
|
|
|
cmds:
|
|
|
|
- docker-compose ...
|
|
|
|
```
|
|
|
|
|
|
|
|
This is also done automatically when using included Taskfiles.
|