getting closer

This commit is contained in:
Mike Farah
2023-04-17 17:23:48 +10:00
parent ee8cc90307
commit cd50b35787
8 changed files with 115 additions and 14 deletions
@@ -27,7 +27,9 @@ will output
```yaml
item_value: &item_value
value: true
thingOne: false
thingOne:
name: item_1
value: false
thingTwo:
name: item_2
!!merge <<: *item_value
@@ -74,6 +74,39 @@ then
yq '[... | {"p": path | join("."), "isKey": is_key, "hc": headComment, "lc": lineComment, "fc": footComment}]' sample.yml
```
will output
```yaml
- p: ""
isKey: false
hc: ""
lc: ""
fc: ""
- p: hello
isKey: null
true: null
hc: null
"": null
lc: null
hello-world-comment: null
fc: null
- p: hello
isKey: false
hc: ""
lc: ""
fc: ""
- p: hello.message
isKey: null
true: null
hc: null
"": null
lc: null
fc: null
- p: hello.message
isKey: false
hc: ""
lc: ""
fc: ""
```
## Retrieve comment - map key example
From the previous example, we know that the comment is on the 'hello' _key_ as a lineComment
@@ -106,6 +139,31 @@ then
yq '[... | {"p": path | join("."), "isKey": is_key, "hc": headComment, "lc": lineComment, "fc": footComment}]' sample.yml
```
will output
```yaml
- p: ""
isKey: false
hc: ""
lc: ""
fc: ""
- p: name
isKey: null
true: null
hc: null
"": null
lc: null
fc: null
- p: name
isKey: false
hc: ""
lc: ""
fc: ""
- p: name.0
isKey: false
hc: under-name-comment
lc: ""
fc: ""
```
## Retrieve comment - array example
From the previous example, we know that the comment is on the first child as a headComment