this repo has no description
0
fork

Configure Feed

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

cmd/cue/cmd: avoid roundtrip when printing non-CUE in eval

Fixes #986

Change-Id: I85961ab2fc23828ad44814479e7057723aed03de
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9862
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>

+51 -6
+15 -6
cmd/cue/cmd/eval.go
··· 20 20 "github.com/spf13/cobra" 21 21 22 22 "cuelang.org/go/cue" 23 + "cuelang.org/go/cue/build" 23 24 "cuelang.org/go/cue/format" 24 25 "cuelang.org/go/internal" 25 26 "cuelang.org/go/internal/encoding" ··· 117 118 } 118 119 v := iter.value() 119 120 121 + errHeader := func() { 122 + if id != "" { 123 + fmt.Fprintf(cmd.OutOrStderr(), "// %s\n", id) 124 + } 125 + } 126 + if b.outFile.Encoding != build.CUE { 127 + err := e.Encode(v) 128 + if err != nil { 129 + errHeader() 130 + exitOnErr(cmd, err, false) 131 + } 132 + continue 133 + } 134 + 120 135 if flagConcrete.Bool(cmd) { 121 136 syn = append(syn, cue.Concrete(true)) 122 137 } 123 138 if flagHidden.Bool(cmd) || flagAll.Bool(cmd) { 124 139 syn = append(syn, cue.Hidden(true)) 125 - } 126 - 127 - errHeader := func() { 128 - if id != "" { 129 - fmt.Fprintf(cmd.OutOrStderr(), "// %s\n", id) 130 - } 131 140 } 132 141 133 142 if len(b.expressions) > 1 {
+36
cmd/cue/cmd/testdata/script/issue986.txt
··· 1 + 2 + # Hidden values are dropped when outputting CUE. This is fine in eval for 3 + # debugging, but not when the final result needs to be compiled again to be 4 + # converted to another format. 5 + 6 + cue eval in.cue --out yaml 7 + cmp stdout expect-stdout 8 + 9 + -- in.cue -- 10 + #Foo: { 11 + a: string 12 + b: string 13 + ab: "\(a)\(b)" 14 + } 15 + 16 + { 17 + a: "aaa" 18 + b: "bbb" 19 + } & #Foo 20 + 21 + #Bar: { 22 + _c: string 23 + _d: string 24 + cd: "\(_c)\(_d)" 25 + } 26 + 27 + { 28 + _c: "ccc" 29 + _d: "ddd" 30 + } & #Bar 31 + 32 + -- expect-stdout -- 33 + a: aaa 34 + b: bbb 35 + ab: aaabbb 36 + cd: cccddd