mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-06 04:45:39 +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
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
[1, 2, null]
|
[1, 2]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Append to existing array
|
## 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:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
- yes
|
[yes, no]
|
||||||
- no
|
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@ -56,6 +56,7 @@ will output
|
|||||||
```yaml
|
```yaml
|
||||||
Mike: cat
|
Mike: cat
|
||||||
Mike: dog
|
Mike: dog
|
||||||
|
---
|
||||||
Rosey: monkey
|
Rosey: monkey
|
||||||
Rosey: sheep
|
Rosey: sheep
|
||||||
```
|
```
|
||||||
|
|||||||
@ -85,6 +85,7 @@ will output
|
|||||||
```yaml
|
```yaml
|
||||||
match: cat
|
match: cat
|
||||||
doc: 0
|
doc: 0
|
||||||
|
---
|
||||||
match: frog
|
match: frog
|
||||||
doc: 1
|
doc: 1
|
||||||
```
|
```
|
||||||
|
|||||||
@ -158,7 +158,9 @@ yq '. *= load_props("../../examples/small.properties")' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
is
|
this:
|
||||||
|
is: a properties file
|
||||||
|
cool: ay
|
||||||
```
|
```
|
||||||
|
|
||||||
## Load from base64 encoded file
|
## Load from base64 encoded file
|
||||||
|
|||||||
@ -18,6 +18,10 @@ func addAssignOperator(d *dataTreeNavigator, context Context, expressionNode *Ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
func toNodes(candidate *CandidateNode, lhs *CandidateNode) []*CandidateNode {
|
func toNodes(candidate *CandidateNode, lhs *CandidateNode) []*CandidateNode {
|
||||||
|
if candidate.Tag == "!!null" {
|
||||||
|
return []*CandidateNode{}
|
||||||
|
}
|
||||||
|
|
||||||
clone := candidate.Copy()
|
clone := candidate.Copy()
|
||||||
|
|
||||||
switch candidate.Kind {
|
switch candidate.Kind {
|
||||||
|
|||||||
@ -49,7 +49,19 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, expres
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, err
|
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
|
return context.ChildContext(newObject), nil
|
||||||
|
|||||||
@ -17,7 +17,7 @@ var createMapOperatorScenarios = []expressionScenario{
|
|||||||
description: "sets key properly",
|
description: "sets key properly",
|
||||||
expression: `("frog": "jumps") | .[0][0] | .frog`,
|
expression: `("frog": "jumps") | .[0][0] | .frog`,
|
||||||
expected: []string{
|
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]}`,
|
document: `{name: Mike, pets: [cat, dog]}`,
|
||||||
expression: `(.name: .pets.[]) | .[0][0] | ..`,
|
expression: `(.name: .pets.[]) | .[0][0] | ..`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::Mike: cat\n",
|
"D0, P[0 0], (!!map)::Mike: cat\n",
|
||||||
"D0, P[Mike], (!!str)::cat\n",
|
"D0, P[0 0 Mike], (!!str)::cat\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ var createMapOperatorScenarios = []expressionScenario{
|
|||||||
document: "pets:\n cows: value",
|
document: "pets:\n cows: value",
|
||||||
expression: `("b":.pets) | .[0][0] | .b.cows`,
|
expression: `("b":.pets) | .[0][0] | .b.cows`,
|
||||||
expected: []string{
|
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