Skip to content

Commit d87f9d4

Browse files
committed
cmd/cue: allow incomplete in vet
To be consistent with eval, the -c option has now to be used to require a complete configuration. Change-Id: I1417ebdcb07a841fe1200a6d1c87696f4c6a6db4 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2361 Reviewed-by: Marcel van Lohuizen <[email protected]>
1 parent 13a9d4d commit d87f9d4

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

cmd/cue/cmd/vet.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"cuelang.org/go/cue/ast"
2020
"cuelang.org/go/cue/parser"
2121
"github.com/spf13/cobra"
22+
"golang.org/x/text/message"
2223
)
2324

2425
func newVetCmd() *cobra.Command {
@@ -27,6 +28,10 @@ func newVetCmd() *cobra.Command {
2728
Short: "validate CUE configurations",
2829
RunE: doVet,
2930
}
31+
32+
cmd.Flags().BoolP(string(flagConcrete), "c", false,
33+
"require the evaluation to be concrete")
34+
3035
return cmd
3136
}
3237

@@ -44,13 +49,31 @@ func doVet(cmd *cobra.Command, args []string) error {
4449

4550
for _, inst := range instances {
4651
// TODO: use ImportPath or some other sanitized path.
52+
53+
concrete := true
54+
hasFlag := false
55+
if flag := cmd.Flag(string(flagConcrete)); flag != nil {
56+
hasFlag = flag.Changed
57+
if hasFlag {
58+
concrete = flagConcrete.Bool(cmd)
59+
}
60+
}
4761
opt := []cue.Option{
4862
cue.Attributes(true),
4963
cue.Optional(true),
50-
cue.Concrete(true),
5164
cue.Hidden(true),
5265
}
53-
err := inst.Value().Validate(opt...)
66+
w := cmd.OutOrStderr()
67+
shown := false
68+
err := inst.Value().Validate(append(opt, cue.Concrete(concrete))...)
69+
if err != nil && !hasFlag {
70+
err = inst.Value().Validate(append(opt, cue.Concrete(false))...)
71+
if !shown && err == nil {
72+
shown = true
73+
p := message.NewPrinter(getLang())
74+
p.Fprintln(w, "some instances are incomplete; use the -c flag to show errors or suppress this message")
75+
}
76+
}
5477
exitIfErr(cmd, inst, err, false)
5578
}
5679
return nil

0 commit comments

Comments
 (0)