this repo has no description
0
fork

Configure Feed

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

cmd/cue/cmd: always print newline at end of eval

format.Node doesn't print a newline after
a single expression.

Change-Id: I87220e0c2a290ffd7618c4633329d3ef614df834
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3521
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>

+18 -8
+12 -8
cmd/cue/cmd/eval.go
··· 15 15 package cmd 16 16 17 17 import ( 18 + "bytes" 18 19 "fmt" 19 20 20 21 "cuelang.org/go/cue" ··· 90 91 } 91 92 92 93 w := cmd.OutOrStdout() 94 + // Always print a trailing newline. format.Node may not write a trailing 95 + // newline if the output is single-line expression. 96 + writeNode := func(b []byte, err error) { 97 + _, _ = w.Write(b) 98 + if !bytes.HasSuffix(b, []byte("\n")) { 99 + w.Write([]byte{'\n'}) 100 + } 101 + } 93 102 94 103 for _, inst := range instances { 95 104 // TODO: use ImportPath or some other sanitized path. ··· 122 131 continue 123 132 } 124 133 } 125 - b, _ := format.Node(getSyntax(v, syn), opts...) 126 - _, _ = w.Write(b) 134 + writeNode(format.Node(getSyntax(v, syn), opts...)) 127 135 } 128 136 for _, e := range exprs { 129 137 if len(exprs) > 1 { 130 138 fmt.Fprint(w, "// ") 131 - b, _ := format.Node(e) 132 - _, _ = w.Write(b) 133 - fmt.Fprintln(w) 139 + writeNode(format.Node(e)) 134 140 } 135 141 v := inst.Eval(e) 136 142 if flagConcrete.Bool(cmd) && !flagIgnore.Bool(cmd) { ··· 139 145 continue 140 146 } 141 147 } 142 - b, _ := format.Node(getSyntax(v, syn), opts...) 143 - _, _ = w.Write(b) 144 - fmt.Fprintln(w) 148 + writeNode(format.Node(getSyntax(v, syn), opts...)) 145 149 } 146 150 } 147 151 return nil
+6
cmd/cue/cmd/testdata/script/eval_newline.txt
··· 1 + cue eval ./data.cue 2 + cmp stdout expect-stdout 3 + -- data.cue -- 4 + 3 5 + -- expect-stdout -- 6 + 3