this repo has no description
0
fork

Configure Feed

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

cmd/cue: support `cue fix -` to fix CUE via stdin and stdout

We were missing the extra few lines of code to handle it,
just like other commands such as `cue fmt` or `cue import`.

Fixes #3417.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Id2d88b32c02e4218db4ad119489b4f68f1f39783
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200554
Reviewed-by: Matthew Sackman <matthew@cue.works>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+17 -6
+9 -4
cmd/cue/cmd/fix.go
··· 89 89 90 90 for _, i := range instances { 91 91 for _, f := range i.Files { 92 - if done[f] || !strings.HasSuffix(f.Filename, ".cue") { 92 + if done[f] || (f.Filename != "-" && !strings.HasSuffix(f.Filename, ".cue")) { 93 93 continue 94 94 } 95 95 done[f] = true ··· 99 99 errs = errors.Append(errs, errors.Promote(err, "format")) 100 100 } 101 101 102 - err = os.WriteFile(f.Filename, b, 0644) 103 - if err != nil { 104 - errs = errors.Append(errs, errors.Promote(err, "write")) 102 + if f.Filename == "-" { 103 + if _, err := cmd.OutOrStdout().Write(b); err != nil { 104 + return err 105 + } 106 + } else { 107 + if err := os.WriteFile(f.Filename, b, 0644); err != nil { 108 + errs = errors.Append(errs, errors.Promote(err, "write")) 109 + } 105 110 } 106 111 } 107 112 }
+8 -2
cmd/cue/cmd/testdata/script/fix.txtar
··· 1 - exec cue fix ./... 1 + # Just like other commands, we can fix with stdin/stdout. 2 + stdin p/three.cue 3 + exec cue fix - 4 + cmp stdout p/three.cue.fixed 5 + 2 6 # Make sure we fix all files in a directory, even if they're a mix of packages (or no packages). 7 + exec cue fix ./... 3 8 cmp p/one.cue p/one.cue.fixed 4 9 cmp p/two.cue p/two.cue.fixed 5 10 cmp p/three.cue p/three.cue.fixed 11 + 6 12 -- p/one.cue -- 7 13 package one 8 14 ··· 28 34 -- p/three.cue.fixed -- 29 35 import "list" 30 36 31 - out: list.Concat([["a"], (list.Concat([(list.Repeat(["a"], 7)), ["gh"]]))]) 37 + out: list.Concat([["a"], (list.Concat([(list.Repeat(["a"], 7)), ["gh"]]))])