compiler: FillFields helper, cleaned up repeated code

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-12-09 15:20:56 -05:00
parent ff6c7d1c1f
commit 0768ac9f3f
5 changed files with 25 additions and 31 deletions

View File

@@ -31,6 +31,17 @@ func (v *Value) FillPath(p cue.Path, x interface{}) error {
return v.val.Err()
}
// FillFields fills multiple fields, in place
func (v *Value) FillFields(values map[string]interface{}) (*Value, error) {
for p, x := range values {
if err := v.FillPath(cue.ParsePath(p), x); err != nil {
return nil, err
}
}
return v, nil
}
// LookupPath is a concurrency safe wrapper around cue.Value.LookupPath
func (v *Value) LookupPath(p cue.Path) *Value {
v.cc.rlock()