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
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
- a
|
a: 1
|
||||||
- 1
|
b: 2
|
||||||
- b
|
|
||||||
- 2
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## from_entries with numeric key indices
|
## from_entries with numeric key indices
|
||||||
@ -80,10 +78,8 @@ yq 'to_entries | from_entries' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
- 0
|
0: a
|
||||||
- a
|
1: b
|
||||||
- 1
|
|
||||||
- b
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use with_entries to update keys
|
## Use with_entries to update keys
|
||||||
@ -97,10 +93,8 @@ yq 'with_entries(.key |= "KEY_" + .)' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
- KEY_a
|
KEY_a: 1
|
||||||
- 1
|
KEY_b: 2
|
||||||
- KEY_b
|
|
||||||
- 2
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Custom sort map keys
|
## Custom sort map keys
|
||||||
@ -116,13 +110,9 @@ yq 'to_entries | sort_by(.key) | reverse | from_entries' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
!!tag
|
c: 3
|
||||||
- c
|
b: 2
|
||||||
- 3
|
a: 1
|
||||||
- b
|
|
||||||
- 2
|
|
||||||
- a
|
|
||||||
- 1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use with_entries to filter the map
|
## Use with_entries to filter the map
|
||||||
@ -136,7 +126,6 @@ yq 'with_entries(select(.value | has("b")))' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
- a
|
a: {b: bird}
|
||||||
- {b: bird}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func parseEntry(candidateNode *CandidateNode, position int) (*CandidateNode, *Ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) {
|
func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) {
|
||||||
var node = candidateNode.CopyWithoutContent()
|
var node = candidateNode.unwrapDocument().CopyWithoutContent()
|
||||||
|
|
||||||
var contents = candidateNode.unwrapDocument().Content
|
var contents = candidateNode.unwrapDocument().Content
|
||||||
|
|
||||||
@ -100,6 +100,8 @@ func fromEntries(candidateNode *CandidateNode) (*CandidateNode, error) {
|
|||||||
|
|
||||||
node.Content = append(node.Content, key, value)
|
node.Content = append(node.Content, key, value)
|
||||||
}
|
}
|
||||||
|
node.Kind = MappingNode
|
||||||
|
node.Tag = "!!map"
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user