this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

all: remove various cue.Value.Lookup usages

Replace various usages of the deprecated cue.Value.Lookup with
cue.Value.LookupPath.

Also, fix some typos and reorganize some imports.

Updates #2480.

Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Change-Id: I8faff629c07601dcb51fda527d8f10b80265bd92
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194951
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>

authored by

Noam Dolovich and committed by
Daniel Martí
38185284 97bf1a6e

+24 -20
+1 -1
cmd/cue/cmd/custom.go
··· 43 43 const commandSection = "command" 44 44 45 45 func lookupString(obj cue.Value, key, def string) string { 46 - str, err := obj.Lookup(key).String() 46 + str, err := obj.LookupPath(cue.MakePath(cue.Str(key))).String() 47 47 if err == nil { 48 48 def = str 49 49 }
+3 -3
encoding/openapi/decode.go
··· 51 51 52 52 v := data.Value() 53 53 54 - doc, _ := v.Lookup("info", "title").String() // Required 55 - if s, _ := v.Lookup("info", "description").String(); s != "" { 54 + doc, _ := v.LookupPath(cue.MakePath(cue.Str("info"), cue.Str("title"))).String() // Required 55 + if s, _ := v.LookupPath(cue.MakePath(cue.Str("info"), cue.Str("description"))).String(); s != "" { 56 56 doc += "\n\n" + s 57 57 } 58 58 cg := internal.NewComment(true, doc) ··· 84 84 // add(internal.NewAttr("openapi", "version="+ version)) 85 85 // } 86 86 87 - if info := v.Lookup("info"); info.Exists() { 87 + if info := v.LookupPath(cue.MakePath(cue.Str("info"))); info.Exists() { 88 88 decls := []interface{}{} 89 89 if st, ok := info.Syntax().(*ast.StructLit); ok { 90 90 // Remove title.
+3 -3
encoding/openapi/openapi.go
··· 165 165 errs = errors.Append(errs, errors.Newf(i.Value().Pos(), 166 166 "info must be a struct")) 167 167 } 168 - title, _ = i.Value().Lookup("title").String() 169 - version, _ = i.Value().Lookup("version").String() 168 + title, _ = i.Value().LookupPath(cue.MakePath(cue.Str("title"))).String() 169 + version, _ = i.Value().LookupPath(cue.MakePath(cue.Str("version"))).String() 170 170 171 171 default: 172 172 errs = errors.Append(errs, errors.Newf(i.Value().Pos(), ··· 186 186 } 187 187 188 188 if version == "" { 189 - version, _ = val.Lookup("$version").String() 189 + version, _ = val.LookupPath(cue.MakePath(cue.Str("$version"))).String() 190 190 if version == "" { 191 191 version = "no version" 192 192 }
+3 -2
encoding/protobuf/jsonpb/decoder.go
··· 18 18 "encoding/base64" 19 19 "strings" 20 20 21 + "github.com/cockroachdb/apd/v3" 22 + 21 23 "cuelang.org/go/cue" 22 24 "cuelang.org/go/cue/ast" 23 25 "cuelang.org/go/cue/ast/astutil" ··· 25 27 "cuelang.org/go/cue/literal" 26 28 "cuelang.org/go/cue/token" 27 29 "cuelang.org/go/encoding/protobuf/pbinternal" 28 - "github.com/cockroachdb/apd/v3" 29 30 ) 30 31 31 32 // Option is an option. ··· 77 78 // according to the protocol buffer to JSON mapping defined in the protocol 78 79 // buffer spec. 79 80 // 80 - // RewriteFile is idempotent, calling it multiples times on an expression gives 81 + // RewriteFile is idempotent, calling it multiple times on an expression gives 81 82 // the same result. 82 83 func (d *Decoder) RewriteFile(file *ast.File) error { 83 84 var r rewriter
+5 -5
pkg/tool/http/http.go
··· 47 47 u = ctx.String("url") 48 48 ) 49 49 var r io.Reader 50 - if obj := ctx.Obj.Lookup("request"); obj.Exists() { 51 - if v := obj.Lookup("body"); v.Exists() { 50 + if obj := ctx.Obj.LookupPath(cue.MakePath(cue.Str("request"))); obj.Exists() { 51 + if v := obj.LookupPath(cue.MakePath(cue.Str("body"))); v.Exists() { 52 52 r, err = v.Reader() 53 53 if err != nil { 54 54 return nil, err ··· 65 65 } 66 66 67 67 var caCert []byte 68 - caCertValue := ctx.Obj.LookupPath(cue.ParsePath("tls.caCert")) 68 + caCertValue := ctx.Obj.LookupPath(cue.MakePath(cue.Str("tls"), cue.Str("caCert"))) 69 69 if caCertValue.Exists() { 70 70 caCert, err = caCertValue.Bytes() 71 71 if err != nil { ··· 74 74 } 75 75 76 76 tlsVerify := true 77 - tlsVerifyValue := ctx.Obj.LookupPath(cue.ParsePath("tls.verify")) 77 + tlsVerifyValue := ctx.Obj.LookupPath(cue.MakePath(cue.Str("tls"), cue.Str("verify"))) 78 78 if tlsVerifyValue.Exists() { 79 79 tlsVerify, err = tlsVerifyValue.Bool() 80 80 if err != nil { ··· 143 143 } 144 144 145 145 func parseHeaders(obj cue.Value, label string) (http.Header, error) { 146 - m := obj.Lookup(label) 146 + m := obj.LookupPath(cue.MakePath(cue.Str(label))) 147 147 if !m.Exists() { 148 148 return nil, nil 149 149 }
+1 -1
pkg/tool/os/env.go
··· 99 99 100 100 for _, kv := range os.Environ() { 101 101 name, str, _ := strings.Cut(kv, "=") 102 - if v := ctx.Obj.Lookup(name); v.Exists() { 102 + if v := ctx.Obj.LookupPath(cue.MakePath(cue.Str(name))); v.Exists() { 103 103 update[name], err = fromString(name, str, v) 104 104 if err != nil { 105 105 return nil, err
+8 -5
tools/flow/flow_test.go
··· 170 170 } 171 171 172 172 func taskFunc(v cue.Value) (flow.Runner, error) { 173 - switch name, err := v.Lookup("$id").String(); name { 173 + idPath := cue.MakePath(cue.Str("$id")) 174 + valPath := cue.MakePath(cue.Str("val")) 175 + 176 + switch name, err := v.LookupPath(idPath).String(); name { 174 177 default: 175 178 if err == nil { 176 179 return flow.RunnerFunc(func(t *flow.Task) error { 177 180 t.Fill(map[string]string{"stdout": "foo"}) 178 181 return nil 179 182 }), nil 180 - } else if v.LookupPath(cue.MakePath(cue.Str("$id"))).Exists() { 183 + } else if v.LookupPath(idPath).Exists() { 181 184 return nil, err 182 185 } 183 186 184 187 case "valToOut": 185 188 return flow.RunnerFunc(func(t *flow.Task) error { 186 - if str, err := t.Value().Lookup("val").String(); err == nil { 189 + if str, err := t.Value().LookupPath(valPath).String(); err == nil { 187 190 t.Fill(map[string]string{"out": str}) 188 191 } 189 192 return nil ··· 216 219 // This task is used to serialize different runners in case 217 220 // non-deterministic scheduling is possible. 218 221 return flow.RunnerFunc(func(t *flow.Task) error { 219 - seq, err := t.Value().Lookup("seq").Int64() 222 + seq, err := t.Value().LookupPath(cue.MakePath(cue.Str("seq"))).Int64() 220 223 if err != nil { 221 224 return err 222 225 } 223 226 224 227 waitSeqNum(seq) 225 228 226 - if str, err := t.Value().Lookup("val").String(); err == nil { 229 + if str, err := t.Value().LookupPath(valPath).String(); err == nil { 227 230 t.Fill(map[string]string{"out": str}) 228 231 } 229 232