cue: Use FillPath everywhere since Fill is now deprecated
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
ca9b031e9e
commit
a8b41c06b7
@ -10,6 +10,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"cuelang.org/go/cue"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/opentracing/opentracing-go"
|
"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 {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
return nil, fmt.Errorf("%s: %w", h.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// FillPath fills the value in-place
|
||||||
func (v *Value) Fill(x interface{}) error {
|
func (v *Value) FillPath(p cue.Path, x interface{}) error {
|
||||||
v.cc.lock()
|
v.cc.lock()
|
||||||
defer v.cc.unlock()
|
defer v.cc.unlock()
|
||||||
|
|
||||||
// If calling Fill() with a Value, we want to use the underlying
|
// If calling Fill() with a Value, we want to use the underlying
|
||||||
// cue.Value to fill.
|
// cue.Value to fill.
|
||||||
if val, ok := x.(*Value); ok {
|
if val, ok := x.(*Value); ok {
|
||||||
v.val = v.val.Fill(val.val)
|
v.val = v.val.FillPath(p, val.val)
|
||||||
} else {
|
} 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
|
// LookupPath is a concurrency safe wrapper around cue.Value.LookupPath
|
||||||
@ -146,30 +146,6 @@ func (v *Value) List() ([]*Value, error) {
|
|||||||
return l, nil
|
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.
|
// Recursive concreteness check.
|
||||||
func (v *Value) IsConcreteR() error {
|
func (v *Value) IsConcreteR() error {
|
||||||
return v.val.Validate(cue.Concrete(true))
|
return v.val.Validate(cue.Concrete(true))
|
||||||
|
@ -93,9 +93,9 @@ func NewDeployment(st *DeploymentState) (*Deployment, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if input.Key == "" {
|
if input.Key == "" {
|
||||||
d.input, err = d.input.Merge(v)
|
err = d.input.FillPath(cue.MakePath(), v)
|
||||||
} else {
|
} else {
|
||||||
d.input, err = d.input.MergeTarget(v, input.Key)
|
err = d.input.FillPath(cue.ParsePath(input.Key), v)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -277,8 +277,7 @@ func (d *Deployment) Up(ctx context.Context, s Solver, _ *UpOpts) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Merge task value into output
|
// Merge task value into output
|
||||||
var err error
|
err := d.output.FillPath(t.Path(), t.Value())
|
||||||
d.output, err = d.output.MergePath(t.Value(), t.Path())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.
|
lg.
|
||||||
Error().
|
Error().
|
||||||
|
Reference in New Issue
Block a user