mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-13 20:15:57 +00:00
Fixed create map issue
This commit is contained in:
parent
82f717226c
commit
d033ad570e
@ -56,7 +56,7 @@ yq '.a + null' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
[1, 2, null]
|
||||
[1, 2]
|
||||
```
|
||||
|
||||
## Append to existing array
|
||||
|
@ -31,8 +31,7 @@ In the yaml 1.2 standard, support for yes/no as booleans was dropped - they are
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
- yes
|
||||
- no
|
||||
[yes, no]
|
||||
```
|
||||
then
|
||||
```bash
|
||||
|
@ -56,6 +56,7 @@ will output
|
||||
```yaml
|
||||
Mike: cat
|
||||
Mike: dog
|
||||
---
|
||||
Rosey: monkey
|
||||
Rosey: sheep
|
||||
```
|
||||
|
@ -85,6 +85,7 @@ will output
|
||||
```yaml
|
||||
match: cat
|
||||
doc: 0
|
||||
---
|
||||
match: frog
|
||||
doc: 1
|
||||
```
|
||||
|
@ -158,7 +158,9 @@ yq '. *= load_props("../../examples/small.properties")' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
is
|
||||
this:
|
||||
is: a properties file
|
||||
cool: ay
|
||||
```
|
||||
|
||||
## Load from base64 encoded file
|
||||
|
@ -18,6 +18,10 @@ func addAssignOperator(d *dataTreeNavigator, context Context, expressionNode *Ex
|
||||
}
|
||||
|
||||
func toNodes(candidate *CandidateNode, lhs *CandidateNode) []*CandidateNode {
|
||||
if candidate.Tag == "!!null" {
|
||||
return []*CandidateNode{}
|
||||
}
|
||||
|
||||
clone := candidate.Copy()
|
||||
|
||||
switch candidate.Kind {
|
||||
|
@ -49,7 +49,19 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, expres
|
||||
if err != nil {
|
||||
return Context{}, err
|
||||
}
|
||||
newObject.PushBackList(additions.MatchingNodes)
|
||||
// we should reset the parents and keys of these top level nodes,
|
||||
// as they are new
|
||||
for el := additions.MatchingNodes.Front(); el != nil; el = el.Next() {
|
||||
addition := el.Value.(*CandidateNode)
|
||||
additionCopy := addition.Copy()
|
||||
|
||||
additionCopy.SetParent(nil)
|
||||
additionCopy.Key = nil
|
||||
|
||||
log.Debugf("-- collectObjectOperation, adding result %v", NodeToString(additionCopy))
|
||||
|
||||
newObject.PushBack(additionCopy)
|
||||
}
|
||||
}
|
||||
|
||||
return context.ChildContext(newObject), nil
|
||||
|
@ -17,7 +17,7 @@ var createMapOperatorScenarios = []expressionScenario{
|
||||
description: "sets key properly",
|
||||
expression: `("frog": "jumps") | .[0][0] | .frog`,
|
||||
expected: []string{
|
||||
"D0, P[frog], (!!str)::jumps\n",
|
||||
"D0, P[0 0 frog], (!!str)::jumps\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -32,8 +32,8 @@ var createMapOperatorScenarios = []expressionScenario{
|
||||
document: `{name: Mike, pets: [cat, dog]}`,
|
||||
expression: `(.name: .pets.[]) | .[0][0] | ..`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::Mike: cat\n",
|
||||
"D0, P[Mike], (!!str)::cat\n",
|
||||
"D0, P[0 0], (!!map)::Mike: cat\n",
|
||||
"D0, P[0 0 Mike], (!!str)::cat\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -41,7 +41,7 @@ var createMapOperatorScenarios = []expressionScenario{
|
||||
document: "pets:\n cows: value",
|
||||
expression: `("b":.pets) | .[0][0] | .b.cows`,
|
||||
expected: []string{
|
||||
"D0, P[b cows], (!!str)::value\n",
|
||||
"D0, P[0 0 b cows], (!!str)::value\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user