mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
fixed entries op
This commit is contained in:
parent
4921302c28
commit
cde32c156b
@ -61,10 +61,8 @@ yq 'to_entries | from_entries' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- a
|
||||
- 1
|
||||
- b
|
||||
- 2
|
||||
a: 1
|
||||
b: 2
|
||||
```
|
||||
|
||||
## from_entries with numeric key indices
|
||||
@ -80,10 +78,8 @@ yq 'to_entries | from_entries' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- 0
|
||||
- a
|
||||
- 1
|
||||
- b
|
||||
0: a
|
||||
1: b
|
||||
```
|
||||
|
||||
## Use with_entries to update keys
|
||||
@ -97,10 +93,8 @@ yq 'with_entries(.key |= "KEY_" + .)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- KEY_a
|
||||
- 1
|
||||
- KEY_b
|
||||
- 2
|
||||
KEY_a: 1
|
||||
KEY_b: 2
|
||||
```
|
||||
|
||||
## Custom sort map keys
|
||||
@ -116,13 +110,9 @@ yq 'to_entries | sort_by(.key) | reverse | from_entries' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
!!tag
|
||||
- c
|
||||
- 3
|
||||
- b
|
||||
- 2
|
||||
- a
|
||||
- 1
|
||||
c: 3
|
||||
b: 2
|
||||
a: 1
|
||||
```
|
||||
|
||||
## Use with_entries to filter the map
|
||||
@ -136,7 +126,6 @@ yq 'with_entries(select(.value | has("b")))' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
- a
|
||||
- {b: bird}
|
||||
a: {b: bird}
|
||||
```
|
||||
|
||||
|
@ -88,7 +88,7 @@ func parseEntry(candidateNode *CandidateNode, position int) (*CandidateNode, *Ca
|
||||
}
|
||||
|
||||
func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) {
|
||||
var node = candidateNode.CopyWithoutContent()
|
||||
var node = candidateNode.unwrapDocument().CopyWithoutContent()
|
||||
|
||||
var contents = candidateNode.unwrapDocument().Content
|
||||
|
||||
@ -100,6 +100,8 @@ func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) {
|
||||
|
||||
node.Content = append(node.Content, key, value)
|
||||
}
|
||||
node.Kind = MappingNode
|
||||
node.Tag = "!!map"
|
||||
return node, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user