cmd/cue/cmd: bug fix: allow vet to combine schema and data
This causes some formatting changes as files are processed
on another code path.
Change-Id: I627f9fa0307e12fbbce448afe4554bcff0d548fa
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6021
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go
index ddeec68..a67fe94 100644
--- a/cmd/cue/cmd/common.go
+++ b/cmd/cue/cmd/common.go
@@ -417,11 +417,6 @@
}
}
- if !p.mergeData && p.schema == nil {
- p.orphaned = append(p.orphaned, b.OrphanedFiles...)
- continue
- }
-
// TODO: this processing could probably be delayed, or at least
// simplified. The main reason to do this here is to allow interpreting
// the --schema/-d flag, while allowing to use this for OpenAPI and
@@ -439,7 +434,7 @@
Tags: f.Tags,
Source: file,
}
- if p.schema != nil && d.Interpretation() == "" {
+ if (!p.mergeData || p.schema != nil) && d.Interpretation() == "" {
switch sub.Encoding {
case build.YAML, build.JSON, build.Text:
p.orphaned = append(p.orphaned, sub)
@@ -456,7 +451,7 @@
}
}
- if !addedUser && len(b.Files) > 1 {
+ if !addedUser && len(b.Files) > 0 {
p.insts = append(p.insts, b)
} else if len(p.orphaned) == 0 {
// Instance with only a single build: just print the file.
diff --git a/cmd/cue/cmd/testdata/script/def_jsonschema.txt b/cmd/cue/cmd/testdata/script/def_jsonschema.txt
index 258ef36..9974959 100644
--- a/cmd/cue/cmd/testdata/script/def_jsonschema.txt
+++ b/cmd/cue/cmd/testdata/script/def_jsonschema.txt
@@ -10,9 +10,12 @@
! cue def jsonschema: bad.json --strict
cmp stderr expect-stderr
-! cue eval data.yaml schema.json
+! cue export data.yaml schema.json
cmp stderr expect-stderr2
+! cue vet data.yaml schema.json
+cmp stderr expect-stderr3
+
-- expect-stdout --
package schema
@@ -68,4 +71,8 @@
age: conflicting values "twenty" and >=0 (mismatched types string and number):
13:7
./data.yaml:1:7
+-- expect-stderr3 --
+age: conflicting values "twenty" and >=0 (mismatched types string and number):
+ 13:7
+ ./data.yaml:1:7
-- cue.mod --
diff --git a/cmd/cue/cmd/testdata/script/def_openapi.txt b/cmd/cue/cmd/testdata/script/def_openapi.txt
index d25aa19..65430d8 100644
--- a/cmd/cue/cmd/testdata/script/def_openapi.txt
+++ b/cmd/cue/cmd/testdata/script/def_openapi.txt
@@ -211,7 +211,6 @@
title: *"My OpenAPI" | string
version: *"v1alpha1" | string
}
-
#Bar: {
foo: #Foo
...
diff --git a/cmd/cue/cmd/testdata/script/def_proto.txt b/cmd/cue/cmd/testdata/script/def_proto.txt
index 684aded..816e9c9 100644
--- a/cmd/cue/cmd/testdata/script/def_proto.txt
+++ b/cmd/cue/cmd/testdata/script/def_proto.txt
@@ -2,7 +2,6 @@
cmp stdout expect-stdout
-- expect-stdout --
-// policy_gen.cue
package api
import "time"
@@ -15,24 +14,21 @@
} @protobuf(1,type=map<string,AttributeValue>)
// Specifies one attribute value with different type.
- #AttributeValue: {
- // The attribute value.
- close({}) | close({
- stringValue: string @protobuf(2,name=string_value)
- }) | close({
- int64Value: int64 @protobuf(3,name=int64_value)
- }) | close({
- doubleValue: float64 @protobuf(4,type=double,name=double_value)
- }) | close({
- boolValue: bool @protobuf(5,name=bool_value)
- }) | close({
- bytesValue: bytes @protobuf(6,name=bytes_value)
- }) | close({
- timestampValue: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
- }) | close({
- // Used for values of type STRING_MAP
- stringMapValue: #StringMap @protobuf(9,name=string_map_value)
- })
+ #AttributeValue: {} | {
+ stringValue: string @protobuf(2,name=string_value)
+ } | {
+ int64Value: int64 @protobuf(3,name=int64_value)
+ } | {
+ doubleValue: float64 @protobuf(4,type=double,name=double_value)
+ } | {
+ boolValue: bool @protobuf(5,name=bool_value)
+ } | {
+ bytesValue: bytes @protobuf(6,name=bytes_value)
+ } | {
+ timestampValue: time.Time @protobuf(7,type=google.protobuf.Timestamp,name=timestamp_value)
+ } | {
+ // Used for values of type STRING_MAP
+ stringMapValue: #StringMap @protobuf(9,name=string_map_value)
}
// Defines a string map.
diff --git a/cmd/cue/cmd/testdata/script/vet_file.txt b/cmd/cue/cmd/testdata/script/vet_file.txt
index d3d90bd..a333535 100644
--- a/cmd/cue/cmd/testdata/script/vet_file.txt
+++ b/cmd/cue/cmd/testdata/script/vet_file.txt
@@ -2,7 +2,7 @@
cmp stderr expect-stderr
! cue vet . ./data.yaml
-cmp stderr expect-stderr
+cmp stderr expect-stderr2
-- expect-stderr --
translations.hello.lang: incomplete value (string):
@@ -10,6 +10,12 @@
translations.hello.lang: conflicting values false and string (mismatched types bool and string):
./data.yaml:13:11
./vet.cue:3:31
+-- expect-stderr2 --
+translations.hello.lang: incomplete value (string):
+ ./vet.cue:3:31
+translations.hello.lang: conflicting values false and string (mismatched types bool and string):
+ ./data.yaml:13:11
+ ./vet.cue:3:31
-- vet.cue --
package foo