diff --git a/cmd/cue/cmd/custom.go b/cmd/cue/cmd/custom.go index 6fd1dcb0153..17b8ed1b833 100644 --- a/cmd/cue/cmd/custom.go +++ b/cmd/cue/cmd/custom.go @@ -43,7 +43,7 @@ import ( const commandSection = "command" func lookupString(obj cue.Value, key, def string) string { - str, err := obj.Lookup(key).String() + str, err := obj.LookupPath(cue.MakePath(cue.Str(key))).String() if err == nil { def = str } diff --git a/encoding/openapi/decode.go b/encoding/openapi/decode.go index e911cc11de0..d60e82d6868 100644 --- a/encoding/openapi/decode.go +++ b/encoding/openapi/decode.go @@ -51,8 +51,8 @@ func Extract(data cue.InstanceOrValue, c *Config) (*ast.File, error) { v := data.Value() - doc, _ := v.Lookup("info", "title").String() // Required - if s, _ := v.Lookup("info", "description").String(); s != "" { + doc, _ := v.LookupPath(cue.MakePath(cue.Str("info"), cue.Str("title"))).String() // Required + if s, _ := v.LookupPath(cue.MakePath(cue.Str("info"), cue.Str("description"))).String(); s != "" { doc += "\n\n" + s } cg := internal.NewComment(true, doc) @@ -84,7 +84,7 @@ func Extract(data cue.InstanceOrValue, c *Config) (*ast.File, error) { // add(internal.NewAttr("openapi", "version="+ version)) // } - if info := v.Lookup("info"); info.Exists() { + if info := v.LookupPath(cue.MakePath(cue.Str("info"))); info.Exists() { decls := []interface{}{} if st, ok := info.Syntax().(*ast.StructLit); ok { // Remove title. diff --git a/encoding/openapi/openapi.go b/encoding/openapi/openapi.go index a39ec92c11d..49d71cd4903 100644 --- a/encoding/openapi/openapi.go +++ b/encoding/openapi/openapi.go @@ -165,8 +165,8 @@ func (c *Config) compose(inst cue.InstanceOrValue, schemas *ast.StructLit) (x *a errs = errors.Append(errs, errors.Newf(i.Value().Pos(), "info must be a struct")) } - title, _ = i.Value().Lookup("title").String() - version, _ = i.Value().Lookup("version").String() + title, _ = i.Value().LookupPath(cue.MakePath(cue.Str("title"))).String() + version, _ = i.Value().LookupPath(cue.MakePath(cue.Str("version"))).String() default: errs = errors.Append(errs, errors.Newf(i.Value().Pos(), @@ -186,7 +186,7 @@ func (c *Config) compose(inst cue.InstanceOrValue, schemas *ast.StructLit) (x *a } if version == "" { - version, _ = val.Lookup("$version").String() + version, _ = val.LookupPath(cue.MakePath(cue.Str("$version"))).String() if version == "" { version = "no version" } diff --git a/encoding/protobuf/jsonpb/decoder.go b/encoding/protobuf/jsonpb/decoder.go index ad4ecc39487..14c55c3ff74 100644 --- a/encoding/protobuf/jsonpb/decoder.go +++ b/encoding/protobuf/jsonpb/decoder.go @@ -18,6 +18,8 @@ import ( "encoding/base64" "strings" + "github.com/cockroachdb/apd/v3" + "cuelang.org/go/cue" "cuelang.org/go/cue/ast" "cuelang.org/go/cue/ast/astutil" @@ -25,7 +27,6 @@ import ( "cuelang.org/go/cue/literal" "cuelang.org/go/cue/token" "cuelang.org/go/encoding/protobuf/pbinternal" - "github.com/cockroachdb/apd/v3" ) // Option is an option. @@ -77,7 +78,7 @@ func NewDecoder(schema cue.Value, options ...Option) *Decoder { // according to the protocol buffer to JSON mapping defined in the protocol // buffer spec. // -// RewriteFile is idempotent, calling it multiples times on an expression gives +// RewriteFile is idempotent, calling it multiple times on an expression gives // the same result. func (d *Decoder) RewriteFile(file *ast.File) error { var r rewriter diff --git a/pkg/tool/http/http.go b/pkg/tool/http/http.go index 2ef3b70d301..83e381e16cb 100644 --- a/pkg/tool/http/http.go +++ b/pkg/tool/http/http.go @@ -47,8 +47,8 @@ func (c *httpCmd) Run(ctx *task.Context) (res interface{}, err error) { u = ctx.String("url") ) var r io.Reader - if obj := ctx.Obj.Lookup("request"); obj.Exists() { - if v := obj.Lookup("body"); v.Exists() { + if obj := ctx.Obj.LookupPath(cue.MakePath(cue.Str("request"))); obj.Exists() { + if v := obj.LookupPath(cue.MakePath(cue.Str("body"))); v.Exists() { r, err = v.Reader() if err != nil { return nil, err @@ -65,7 +65,7 @@ func (c *httpCmd) Run(ctx *task.Context) (res interface{}, err error) { } var caCert []byte - caCertValue := ctx.Obj.LookupPath(cue.ParsePath("tls.caCert")) + caCertValue := ctx.Obj.LookupPath(cue.MakePath(cue.Str("tls"), cue.Str("caCert"))) if caCertValue.Exists() { caCert, err = caCertValue.Bytes() if err != nil { @@ -74,7 +74,7 @@ func (c *httpCmd) Run(ctx *task.Context) (res interface{}, err error) { } tlsVerify := true - tlsVerifyValue := ctx.Obj.LookupPath(cue.ParsePath("tls.verify")) + tlsVerifyValue := ctx.Obj.LookupPath(cue.MakePath(cue.Str("tls"), cue.Str("verify"))) if tlsVerifyValue.Exists() { tlsVerify, err = tlsVerifyValue.Bool() if err != nil { @@ -143,7 +143,7 @@ func (c *httpCmd) Run(ctx *task.Context) (res interface{}, err error) { } func parseHeaders(obj cue.Value, label string) (http.Header, error) { - m := obj.Lookup(label) + m := obj.LookupPath(cue.MakePath(cue.Str(label))) if !m.Exists() { return nil, nil } diff --git a/pkg/tool/os/env.go b/pkg/tool/os/env.go index 40cdc8e6cbd..270ae3dc2ae 100644 --- a/pkg/tool/os/env.go +++ b/pkg/tool/os/env.go @@ -99,7 +99,7 @@ func (c *environCmd) Run(ctx *task.Context) (res interface{}, err error) { for _, kv := range os.Environ() { name, str, _ := strings.Cut(kv, "=") - if v := ctx.Obj.Lookup(name); v.Exists() { + if v := ctx.Obj.LookupPath(cue.MakePath(cue.Str(name))); v.Exists() { update[name], err = fromString(name, str, v) if err != nil { return nil, err diff --git a/tools/flow/flow_test.go b/tools/flow/flow_test.go index 14fdaf007c5..9762839875b 100644 --- a/tools/flow/flow_test.go +++ b/tools/flow/flow_test.go @@ -170,20 +170,23 @@ func TestFlowValuePanic(t *testing.T) { } func taskFunc(v cue.Value) (flow.Runner, error) { - switch name, err := v.Lookup("$id").String(); name { + idPath := cue.MakePath(cue.Str("$id")) + valPath := cue.MakePath(cue.Str("val")) + + switch name, err := v.LookupPath(idPath).String(); name { default: if err == nil { return flow.RunnerFunc(func(t *flow.Task) error { t.Fill(map[string]string{"stdout": "foo"}) return nil }), nil - } else if v.LookupPath(cue.MakePath(cue.Str("$id"))).Exists() { + } else if v.LookupPath(idPath).Exists() { return nil, err } case "valToOut": return flow.RunnerFunc(func(t *flow.Task) error { - if str, err := t.Value().Lookup("val").String(); err == nil { + if str, err := t.Value().LookupPath(valPath).String(); err == nil { t.Fill(map[string]string{"out": str}) } return nil @@ -216,14 +219,14 @@ func taskFunc(v cue.Value) (flow.Runner, error) { // This task is used to serialize different runners in case // non-deterministic scheduling is possible. return flow.RunnerFunc(func(t *flow.Task) error { - seq, err := t.Value().Lookup("seq").Int64() + seq, err := t.Value().LookupPath(cue.MakePath(cue.Str("seq"))).Int64() if err != nil { return err } waitSeqNum(seq) - if str, err := t.Value().Lookup("val").String(); err == nil { + if str, err := t.Value().LookupPath(valPath).String(); err == nil { t.Fill(map[string]string{"out": str}) }