Added key operator

This commit is contained in:
Mike Farah
2021-11-24 09:57:35 +11:00
parent 7f629d5e36
commit b44fecdfa5
27 changed files with 149 additions and 48 deletions
+35
View File
@@ -34,3 +34,38 @@ will output
- 1
```
## Update map key
Given a sample.yml file of:
```yaml
a:
x: 3
y: 4
```
then
```bash
yq eval '(.a.x | key) = "meow"' sample.yml
```
will output
```yaml
a:
meow: 3
y: 4
```
## Get comment from map key
Given a sample.yml file of:
```yaml
a:
# comment on key
x: 3
y: 4
```
then
```bash
yq eval '.a.x | key | headComment' sample.yml
```
will output
```yaml
comment on key
```