Skip to content

Commit 5cfb09f

Browse files
committed
docs: remove map variables experiment page and update usage to include map variable info
1 parent 834afe2 commit 5cfb09f

File tree

2 files changed

+45
-283
lines changed

2 files changed

+45
-283
lines changed

website/docs/experiments/map_variables.mdx

Lines changed: 0 additions & 245 deletions
This file was deleted.

website/docs/usage.mdx

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,53 +1144,38 @@ variable types are supported:
11441144
- `int`
11451145
- `float`
11461146
- `array`
1147+
- `map`
11471148

11481149
:::note
11491150

1150-
Maps are not supported by default, but there is an
1151-
[experiment][map-variables] that can be enabled to add support. If
1152-
you're interested in this functionality, we would appreciate your feedback.
1153-
:pray:
1151+
Defining a map requires that you use a special `map` subkey (see example below).
11541152

1155-
In the meantime, it is technically possible to define a map using a `ref` resolver and a templating function. For example:
1156-
1157-
```yaml
1158-
version: '3'
1159-
1160-
tasks:
1161-
task-with-map:
1162-
vars:
1163-
FOO:
1164-
ref: dict "a" "1" "b" "2" "c" "3"
1165-
cmds:
1166-
- echo {{.FOO}}
1167-
```
1168-
1169-
```txt
1170-
map[a:1 b:2 c:3]
1171-
```
1172-
1173-
OR by using the same technique with JSON:
1153+
:::
11741154

11751155
```yaml
1176-
version: '3'
1156+
version: 3
11771157
11781158
tasks:
1179-
task-with-map:
1159+
foo:
11801160
vars:
1181-
JSON: '{"a": 1, "b": 2, "c": 3}'
1182-
FOO:
1183-
ref: "fromJson .JSON"
1184-
cmds:
1185-
- echo {{.FOO}}
1161+
STRING: 'Hello, World!'
1162+
BOOL: true
1163+
INT: 42
1164+
FLOAT: 3.14
1165+
ARRAY: [1, 2, 3]
1166+
MAP:
1167+
map: {A: 1, B: 2, C: 3}
1168+
cmds:
1169+
- 'echo {{.STRING}}' # Hello, World!
1170+
- 'echo {{.BOOL}}' # true
1171+
- 'echo {{.INT}}' # 42
1172+
- 'echo {{.FLOAT}}' # 3.14
1173+
- 'echo {{.ARRAY}}' # [1 2 3]
1174+
- 'echo {{.ARRAY.0}}' # 1
1175+
- 'echo {{.MAP}}' # map[A:1 B:2 C:3]
1176+
- 'echo {{.MAP.A}}' # 1
11861177
```
11871178

1188-
```txt
1189-
map[a:1 b:2 c:3]
1190-
```
1191-
1192-
:::
1193-
11941179
Variables can be set in many places in a Taskfile. When executing
11951180
[templates][templating-reference], Task will look for variables in the order
11961181
listed below (most important first):
@@ -1391,6 +1376,29 @@ tasks:
13911376
- 'echo {{.FOO}}' # <-- FOO is just the letter 'A'
13921377
```
13931378

1379+
### Parsing JSON/YAML into map variables
1380+
1381+
If you have a raw JSON or YAML string that you want to process in Task, you can
1382+
use a combination of the `ref` keyword and the `fromJson` or `fromYaml`
1383+
templating functions to parse the string into a map variable. For example:
1384+
1385+
```yaml
1386+
version: '3'
1387+
1388+
tasks:
1389+
task-with-map:
1390+
vars:
1391+
JSON: '{"a": 1, "b": 2, "c": 3}'
1392+
FOO:
1393+
ref: "fromJson .JSON"
1394+
cmds:
1395+
- echo {{.FOO}}
1396+
```
1397+
1398+
```txt
1399+
map[a:1 b:2 c:3]
1400+
```
1401+
13941402
## Looping over values
13951403

13961404
Task allows you to loop over certain values and execute a command for each.
@@ -1518,7 +1526,7 @@ tasks:
15181526
cmd: cat {{.ITEM}}
15191527
```
15201528

1521-
You can also loop over arrays directly and maps:
1529+
You can also loop over arrays and maps directly:
15221530

15231531
```yaml
15241532
version: 3
@@ -2327,6 +2335,5 @@ if called by another task, either directly or as a dependency.
23272335

23282336
{/* prettier-ignore-start */}
23292337
[gotemplate]: https://golang.org/pkg/text/template/
2330-
[map-variables]: ./experiments/map_variables.mdx
23312338
[templating-reference]: ./reference/templating.mdx
23322339
{/* prettier-ignore-end */}

0 commit comments

Comments
 (0)