cmd/cue: more streamlined printing
- don't print headers for single instances
(in some circumstances)
- don't print errors if they are to be ignored.
- omit extra newline for eval
- remove duplicate header for vet
Issue #52
Change-Id: Idb901f80bbc33173aa357e0a53d62291c852fa7c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2173
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go
index 6f74ced..c301eea 100644
--- a/cmd/cue/cmd/common.go
+++ b/cmd/cue/cmd/common.go
@@ -99,6 +99,10 @@
exitIfErr(cmd, inst, inst.Err, true)
}
+ if flagIgnore.Bool(cmd) {
+ return instances
+ }
+
// TODO check errors after the fact in case of ignore.
for _, inst := range instances {
// TODO: consider merging errors of multiple files, but ensure
diff --git a/cmd/cue/cmd/eval.go b/cmd/cue/cmd/eval.go
index 2d154ea..1f282dd 100644
--- a/cmd/cue/cmd/eval.go
+++ b/cmd/cue/cmd/eval.go
@@ -93,7 +93,9 @@
for _, inst := range instances {
// TODO: use ImportPath or some other sanitized path.
- fmt.Fprintf(w, "// %s\n", inst.Dir)
+ if len(instances) > 1 {
+ fmt.Fprintf(w, "\n// %s\n", inst.Dir)
+ }
syn := []cue.Option{
cue.Attributes(flagAttributes.Bool(cmd)),
cue.Optional(flagAll.Bool(cmd) || flagOptional.Bool(cmd)),
@@ -120,11 +122,9 @@
continue
}
format.Node(w, getSyntax(v, syn), opts...)
- fmt.Fprintln(w)
}
for _, e := range exprs {
format.Node(w, getSyntax(inst.Eval(e), syn), opts...)
- fmt.Fprintln(w)
}
}
return nil
diff --git a/cmd/cue/cmd/testdata/hello/eval.out b/cmd/cue/cmd/testdata/hello/eval.out
index 0c32af3..1ed63b3 100644
--- a/cmd/cue/cmd/testdata/hello/eval.out
+++ b/cmd/cue/cmd/testdata/hello/eval.out
@@ -1,4 +1,2 @@
-// $CWD/testdata/hello
who: "World"
message: "Hello World!"
-
diff --git a/cmd/cue/cmd/testdata/partial/eval.out b/cmd/cue/cmd/testdata/partial/eval.out
index fd0cf4d..73d0294 100644
--- a/cmd/cue/cmd/testdata/partial/eval.out
+++ b/cmd/cue/cmd/testdata/partial/eval.out
@@ -1,4 +1,3 @@
-// $CWD/testdata/partial
def: 1
sum: 1 | 2
A = a
@@ -20,4 +19,3 @@
}
str: "b"
}
-
diff --git a/cmd/cue/cmd/testdata/tasks/eval.out b/cmd/cue/cmd/testdata/tasks/eval.out
index e883d86..aefec3e 100644
--- a/cmd/cue/cmd/testdata/tasks/eval.out
+++ b/cmd/cue/cmd/testdata/tasks/eval.out
@@ -1,3 +1 @@
-// $CWD/testdata/tasks
message: "Hello world!"
-
diff --git a/cmd/cue/cmd/vet.go b/cmd/cue/cmd/vet.go
index 962743f..c16a452 100644
--- a/cmd/cue/cmd/vet.go
+++ b/cmd/cue/cmd/vet.go
@@ -15,8 +15,6 @@
package cmd
import (
- "os"
-
"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/parser"
@@ -44,10 +42,6 @@
exprs = append(exprs, expr)
}
- w := cmd.OutOrStdout()
-
- cwd, _ := os.Getwd()
-
for _, inst := range instances {
// TODO: use ImportPath or some other sanitized path.
opt := []cue.Option{
@@ -57,9 +51,6 @@
cue.Hidden(true),
}
err := inst.Value().Validate(opt...)
- if flagVerbose.Bool(cmd) || err != nil {
- printHeader(w, cwd, inst.Dir)
- }
exitIfErr(cmd, inst, err, false)
}
return nil