mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-23 22:25:42 +00:00
Fixed null issue with entry operators
This commit is contained in:
parent
6c3965dca3
commit
a2bd463a91
@ -35,6 +35,19 @@ will output
|
|||||||
value: b
|
value: b
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## to_entries null
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
null
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq eval 'to_entries' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
```
|
||||||
|
|
||||||
## from_entries map
|
## from_entries map
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -59,7 +59,9 @@ func toEntriesOperator(d *dataTreeNavigator, context Context, expressionNode *Ex
|
|||||||
case yaml.SequenceNode:
|
case yaml.SequenceNode:
|
||||||
results.PushBack(toEntriesfromSeq(candidate))
|
results.PushBack(toEntriesfromSeq(candidate))
|
||||||
default:
|
default:
|
||||||
return Context{}, fmt.Errorf("%v has no keys", candidate.Node.Tag)
|
if candidateNode.Tag != "!!null" {
|
||||||
|
return Context{}, fmt.Errorf("%v has no keys", candidate.Node.Tag)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,26 +135,26 @@ func withEntriesOperator(d *dataTreeNavigator, context Context, expressionNode *
|
|||||||
//to_entries on the context
|
//to_entries on the context
|
||||||
toEntries, err := toEntriesOperator(d, context, expressionNode)
|
toEntries, err := toEntriesOperator(d, context, expressionNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, nil
|
return Context{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//run expression against entries
|
//run expression against entries
|
||||||
// splat toEntries and pipe it into Rhs
|
// splat toEntries and pipe it into Rhs
|
||||||
splatted, err := splat(d, toEntries, traversePreferences{})
|
splatted, err := splat(d, toEntries, traversePreferences{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, nil
|
return Context{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := d.GetMatchingNodes(splatted, expressionNode.Rhs)
|
result, err := d.GetMatchingNodes(splatted, expressionNode.Rhs)
|
||||||
log.Debug("expressionNode.Rhs %v", expressionNode.Rhs.Operation.OperationType)
|
log.Debug("expressionNode.Rhs %v", expressionNode.Rhs.Operation.OperationType)
|
||||||
log.Debug("result %v", result)
|
log.Debug("result %v", result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, nil
|
return Context{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
collected, err := collectOperator(d, result, expressionNode)
|
collected, err := collectOperator(d, result, expressionNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Context{}, nil
|
return Context{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//from_entries on the result
|
//from_entries on the result
|
||||||
|
@ -21,6 +21,13 @@ var entriesOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (!!seq)::- key: 0\n value: a\n- key: 1\n value: b\n",
|
"D0, P[], (!!seq)::- key: 0\n value: a\n- key: 1\n value: b\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "to_entries null",
|
||||||
|
document: `null`,
|
||||||
|
expression: `to_entries`,
|
||||||
|
expected: []string{
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "from_entries map",
|
description: "from_entries map",
|
||||||
document: `{a: 1, b: 2}`,
|
document: `{a: 1, b: 2}`,
|
||||||
|
Loading…
Reference in New Issue
Block a user