cue: Use FillPath everywhere since Fill is now deprecated

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2021-03-31 13:14:36 -07:00
parent ca9b031e9e
commit a8b41c06b7
3 changed files with 10 additions and 34 deletions

View File

@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"cuelang.org/go/cue"
"golang.org/x/sync/errgroup"
"github.com/opentracing/opentracing-go"
@ -206,7 +207,7 @@ func (c *Client) outputfn(ctx context.Context, r io.Reader) (*compiler.Value, er
if err != nil {
return nil, err
}
if err := out.Fill(v); err != nil {
if err := out.FillPath(cue.MakePath(), v); err != nil {
return nil, fmt.Errorf("%s: %w", h.Name, err)
}
}

View File

@ -31,19 +31,19 @@ func wrapValue(v cue.Value, inst *cue.Instance, cc *Compiler) *Value {
}
}
// Fill the value in-place, unlike Merge which returns a copy.
func (v *Value) Fill(x interface{}) error {
// FillPath fills the value in-place
func (v *Value) FillPath(p cue.Path, x interface{}) error {
v.cc.lock()
defer v.cc.unlock()
// If calling Fill() with a Value, we want to use the underlying
// cue.Value to fill.
if val, ok := x.(*Value); ok {
v.val = v.val.Fill(val.val)
v.val = v.val.FillPath(p, val.val)
} else {
v.val = v.val.Fill(x)
v.val = v.val.FillPath(p, x)
}
return v.Validate()
return v.val.Err()
}
// LookupPath is a concurrency safe wrapper around cue.Value.LookupPath
@ -146,30 +146,6 @@ func (v *Value) List() ([]*Value, error) {
return l, nil
}
// FIXME: receive string path?
func (v *Value) Merge(x interface{}, path ...string) (*Value, error) {
if xval, ok := x.(*Value); ok {
x = xval.val
}
v.cc.lock()
result := v.Wrap(v.val.Fill(x, path...))
v.cc.unlock()
return result, result.Validate()
}
func (v *Value) MergePath(x interface{}, p cue.Path) (*Value, error) {
// FIXME: array indexes and defs are not supported,
// they will be silently converted to regular fields.
// eg. `foo.#bar[0]` will become `foo["#bar"]["0"]`
return v.Merge(x, cuePathToStrings(p)...)
}
func (v *Value) MergeTarget(x interface{}, target string) (*Value, error) {
return v.MergePath(x, cue.ParsePath(target))
}
// Recursive concreteness check.
func (v *Value) IsConcreteR() error {
return v.val.Validate(cue.Concrete(true))

View File

@ -93,9 +93,9 @@ func NewDeployment(st *DeploymentState) (*Deployment, error) {
return nil, err
}
if input.Key == "" {
d.input, err = d.input.Merge(v)
err = d.input.FillPath(cue.MakePath(), v)
} else {
d.input, err = d.input.MergeTarget(v, input.Key)
err = d.input.FillPath(cue.ParsePath(input.Key), v)
}
if err != nil {
return nil, err
@ -277,8 +277,7 @@ func (d *Deployment) Up(ctx context.Context, s Solver, _ *UpOpts) error {
return nil
}
// Merge task value into output
var err error
d.output, err = d.output.MergePath(t.Value(), t.Path())
err := d.output.FillPath(t.Path(), t.Value())
if err != nil {
lg.
Error().