diff --git a/cmd/cue/cmd/testdata/script/export_yaml_comments.txt b/cmd/cue/cmd/testdata/script/export_yaml_comments.txt new file mode 100644 index 00000000000..9a92c959e0a --- /dev/null +++ b/cmd/cue/cmd/testdata/script/export_yaml_comments.txt @@ -0,0 +1,18 @@ +cue export --out yaml ./hello +cmp stdout expect-stdout +-- expect-stdout -- +# cloud-config +foo: bar +hello: + # occupy + world: from mars? +-- hello/hello.cue -- +package hello + +//cloud-config +foo: "bar" + +hello: { + // occupy + world: "from mars?" +} diff --git a/cue/types.go b/cue/types.go index 11528bef192..c67e2ec0335 100644 --- a/cue/types.go +++ b/cue/types.go @@ -2139,7 +2139,7 @@ func All() Option { // Docs indicates whether docs should be included. func Docs(include bool) Option { - return func(p *options) { p.docs = true } + return func(p *options) { p.docs = include } } // Definitions indicates whether definitions should be included. diff --git a/pkg/encoding/yaml/manual.go b/pkg/encoding/yaml/manual.go index ee228f93a2e..7db33cb7224 100644 --- a/pkg/encoding/yaml/manual.go +++ b/pkg/encoding/yaml/manual.go @@ -35,7 +35,7 @@ func Marshal(v cue.Value) (string, error) { // messages can be passed. return "", internal.ErrIncomplete } - n := v.Syntax(cue.Final(), cue.Concrete(true)) + n := v.Syntax(cue.Final(), cue.Concrete(true), cue.Docs(true)) b, err := cueyaml.Encode(n) return string(b), err } @@ -53,7 +53,7 @@ func MarshalStream(v cue.Value) (string, error) { buf.WriteString("---\n") } v := iter.Value() - if err := v.Validate(cue.Concrete(true)); err != nil { + if err := v.Validate(cue.Concrete(true), cue.Docs(true)); err != nil { if err := v.Validate(); err != nil { return "", err }