Skip to content

Commit

Permalink
docs: small adjustment for #1220
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynering committed Jul 25, 2023
1 parent ca72f3c commit a16a5ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ There are some special variables that is available on the templating system:
| `CHECKSUM` | The checksum of the files listed in `sources`. Only available within the `status` prop and if method is set to `checksum`. |
| `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |
| `TASK_VERSION` | The current version of task. |
| `ITEM` | The value of the current iteration when using the `for` property. |
| `ITEM` | The value of the current iteration when using the `for` property. Can be changed to a different variable name using `as:`. |

## ENV

Expand Down
42 changes: 19 additions & 23 deletions docs/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,9 @@ match that glob.

Source paths will always be returned as paths relative to the task directory. If
you need to convert this to an absolute path, you can use the built-in
`joinPath` function:
`joinPath` function.
There are some [special variables](/api/#special-variables) that you may find
useful for this.

```yaml
version: '3'
Expand All @@ -1058,7 +1060,7 @@ tasks:
- bar.txt
cmds:
- for: sources
cmd: cat {{ joinPath .MY_DIR .ITEM }}
cmd: cat {{joinPath .MY_DIR .ITEM}}
```

### Looping over variables
Expand All @@ -1073,11 +1075,10 @@ version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
MY_VAR: foo.txt bar.txt
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
- for: { var: MY_VAR }
cmd: cat {{.ITEM}}
```

If you need to split on a different character, you can do this by specifying the
Expand All @@ -1089,12 +1090,10 @@ version: '3'
tasks:
default:
vars:
my_var: foo.txt,bar.txt
MY_VAR: foo.txt,bar.txt
cmds:
- for:
var: my_var
split: ','
cmd: cat {{ .ITEM }}
- for: { var: MY_VAR, split: ',' }
cmd: cat {{.ITEM}}
```

All of this also works with dynamic variables!
Expand All @@ -1105,12 +1104,11 @@ version: '3'
tasks:
default:
vars:
my_var:
MY_VAR:
sh: find -type f -name '*.txt'
cmds:
- for:
var: my_var
cmd: cat {{ .ITEM }}
- for: { var: MY_VAR }
cmd: cat {{.ITEM}}
```

### Renaming variables
Expand All @@ -1124,12 +1122,10 @@ version: '3'
tasks:
default:
vars:
my_var: foo.txt bar.txt
MY_VAR: foo.txt bar.txt
cmds:
- for:
var: my_var
as: FILE
cmd: cat {{ .FILE }}
- for: { var: MY_VAR, as: FILE }
cmd: cat {{.FILE}}
```

### Looping over tasks
Expand All @@ -1147,11 +1143,11 @@ tasks:
- for: [foo, bar]
task: my-task
vars:
FILE: '{{ .ITEM }}'
FILE: '{{.ITEM}}'
my-task:
cmds:
- echo '{{ .FILE }}'
- echo '{{.FILE}}'
```

Or if you want to run different tasks depending on the value of the loop:
Expand All @@ -1163,7 +1159,7 @@ tasks:
default:
cmds:
- for: [foo, bar]
task: task-{{ .ITEM }}
task: task-{{.ITEM}}
task-foo:
cmds:
Expand Down

0 comments on commit a16a5ea

Please sign in to comment.