mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +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
|
||||
```
|
||||
|
||||
## 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
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
|
@ -59,7 +59,9 @@ func toEntriesOperator(d *dataTreeNavigator, context Context, expressionNode *Ex
|
||||
case yaml.SequenceNode:
|
||||
results.PushBack(toEntriesfromSeq(candidate))
|
||||
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
|
||||
toEntries, err := toEntriesOperator(d, context, expressionNode)
|
||||
if err != nil {
|
||||
return Context{}, nil
|
||||
return Context{}, err
|
||||
}
|
||||
|
||||
//run expression against entries
|
||||
// splat toEntries and pipe it into Rhs
|
||||
splatted, err := splat(d, toEntries, traversePreferences{})
|
||||
if err != nil {
|
||||
return Context{}, nil
|
||||
return Context{}, err
|
||||
}
|
||||
|
||||
result, err := d.GetMatchingNodes(splatted, expressionNode.Rhs)
|
||||
log.Debug("expressionNode.Rhs %v", expressionNode.Rhs.Operation.OperationType)
|
||||
log.Debug("result %v", result)
|
||||
if err != nil {
|
||||
return Context{}, nil
|
||||
return Context{}, err
|
||||
}
|
||||
|
||||
collected, err := collectOperator(d, result, expressionNode)
|
||||
if err != nil {
|
||||
return Context{}, nil
|
||||
return Context{}, err
|
||||
}
|
||||
|
||||
//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",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "to_entries null",
|
||||
document: `null`,
|
||||
expression: `to_entries`,
|
||||
expected: []string{
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "from_entries map",
|
||||
document: `{a: 1, b: 2}`,
|
||||
|
Loading…
Reference in New Issue
Block a user