Skip to content

Commit c8f9f5e

Browse files
authored
Added an example of a default value usage in vars
It's rather often than not you need to use a default value for a variable, and then adjust it to your needs. There's no documentation can be found on how to achieve that so this PR should address this issue
1 parent fe09c01 commit c8f9f5e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

website/docs/usage.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,28 @@ tasks:
12121212
- echo "{{.GREETING}}"
12131213
```
12141214

1215+
Example of a `default` value to be overriden from CLI:
1216+
1217+
```yaml
1218+
version: '3'
1219+
1220+
greet_user:
1221+
desc: "Greet the user with a name."
1222+
vars:
1223+
USER_NAME: '{{.USER_NAME| default "DefaultUser"}}'
1224+
cmds:
1225+
- echo "Hello, {{.USER_NAME}}!"
1226+
```
1227+
1228+
```shell
1229+
$ task greet_user
1230+
task: [greet_user] echo "Hello, DefaultUser!"
1231+
Hello, DefaultUser!
1232+
$ task greet_user USER_NAME="Bob"
1233+
task: [greet_user] echo "Hello, Bob!"
1234+
Hello, Bob!
1235+
```
1236+
12151237
### Dynamic variables
12161238

12171239
The below syntax (`sh:` prop in a variable) is considered a dynamic variable.

0 commit comments

Comments
 (0)