Skip to content

Commit

Permalink
cmd/export: emit comments by default
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Geisendörfer <[email protected]>
  • Loading branch information
felixge committed Feb 28, 2022
1 parent 9b0de10 commit 7541204
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 38 deletions.
17 changes: 8 additions & 9 deletions cmd/cue/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,15 +719,14 @@ func (b *buildPlan) parseFlags() (err error) {
b.cfg.fileFilter = s
}
b.encConfig = &encoding.Config{
Force: flagForce.Bool(b.cmd),
Mode: b.cfg.outMode,
Stdin: b.cmd.InOrStdin(),
Stdout: b.cmd.OutOrStdout(),
ProtoPath: flagProtoPath.StringArray(b.cmd),
AllErrors: flagAllErrors.Bool(b.cmd),
PkgName: flagPackage.String(b.cmd),
Strict: flagStrict.Bool(b.cmd),
PreserveComments: flagPreserveComments.Bool(b.cmd),
Force: flagForce.Bool(b.cmd),
Mode: b.cfg.outMode,
Stdin: b.cmd.InOrStdin(),
Stdout: b.cmd.OutOrStdout(),
ProtoPath: flagProtoPath.StringArray(b.cmd),
AllErrors: flagAllErrors.Bool(b.cmd),
PkgName: flagPackage.String(b.cmd),
Strict: flagStrict.Bool(b.cmd),
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion cmd/cue/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ yaml output as YAML
addOrphanFlags(cmd.Flags())
addInjectionFlags(cmd.Flags(), false)

cmd.Flags().Bool(string(flagPreserveComments), false, "include comments in output")
cmd.Flags().Bool(string(flagEscape), false, "use HTML escaping")
cmd.Flags().StringArrayP(string(flagExpression), "e", nil, "export this expression only")

Expand Down
25 changes: 12 additions & 13 deletions cmd/cue/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ import (

// Common flags
const (
flagAll flagName = "all"
flagDryrun flagName = "dryrun"
flagVerbose flagName = "verbose"
flagAllErrors flagName = "all-errors"
flagTrace flagName = "trace"
flagForce flagName = "force"
flagIgnore flagName = "ignore"
flagStrict flagName = "strict"
flagSimplify flagName = "simplify"
flagPackage flagName = "package"
flagInject flagName = "inject"
flagInjectVars flagName = "inject-vars"
flagPreserveComments flagName = "preserve-comments"
flagAll flagName = "all"
flagDryrun flagName = "dryrun"
flagVerbose flagName = "verbose"
flagAllErrors flagName = "all-errors"
flagTrace flagName = "trace"
flagForce flagName = "force"
flagIgnore flagName = "ignore"
flagStrict flagName = "strict"
flagSimplify flagName = "simplify"
flagPackage flagName = "package"
flagInject flagName = "inject"
flagInjectVars flagName = "inject-vars"

flagExpression flagName = "expression"
flagSchema flagName = "schema"
Expand Down
2 changes: 1 addition & 1 deletion cmd/cue/cmd/testdata/script/export_yaml_comments.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cue export --preserve-comments --out yaml ./hello
cue export --out yaml ./hello
cmp stdout expect-stdout
-- expect-stdout --
# cloud-config
Expand Down
2 changes: 1 addition & 1 deletion cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,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.
Expand Down
2 changes: 1 addition & 1 deletion internal/encoding/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func NewEncoder(f *build.File, cfg *Config) (*Encoder, error) {
}
streamed = true

str, err := yaml.Marshal(v, cue.Docs(e.cfg.PreserveComments))
str, err := yaml.Marshal(v)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions internal/encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ type Config struct {

PkgName string // package name for files to generate

Force bool // overwrite existing files.
Strict bool
Stream bool // will potentially write more than one document per file
AllErrors bool
PreserveComments bool
Force bool // overwrite existing files.
Strict bool
Stream bool // will potentially write more than one document per file
AllErrors bool

Schema cue.Value // used for schema-based decoding

Expand Down
12 changes: 5 additions & 7 deletions pkg/encoding/yaml/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// Marshal returns the YAML encoding of v.
func Marshal(v cue.Value, opts ...cue.Option) (string, error) {
func Marshal(v cue.Value) (string, error) {
if err := v.Validate(cue.Concrete(true)); err != nil {
if err := v.Validate(); err != nil {
return "", err
Expand All @@ -35,14 +35,13 @@ func Marshal(v cue.Value, opts ...cue.Option) (string, error) {
// messages can be passed.
return "", internal.ErrIncomplete
}
opts = append([]cue.Option{cue.Final(), cue.Concrete(true)}, opts...)
n := v.Syntax(opts...)
n := v.Syntax(cue.Final(), cue.Concrete(true), cue.Docs(true))
b, err := cueyaml.Encode(n)
return string(b), err
}

// MarshalStream returns the YAML encoding of v.
func MarshalStream(v cue.Value, opts ...cue.Option) (string, error) {
func MarshalStream(v cue.Value) (string, error) {
// TODO: return an io.Reader and allow asynchronous processing.
iter, err := v.List()
if err != nil {
Expand All @@ -54,16 +53,15 @@ func MarshalStream(v cue.Value, opts ...cue.Option) (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
}
// TODO: allow adt.Bottom to implement errors.Error so that code and
// messages can be passed.
return "", internal.ErrIncomplete
}
opts = append([]cue.Option{cue.Final(), cue.Concrete(true)}, opts...)
n := v.Syntax(opts...)
n := v.Syntax(cue.Final(), cue.Concrete(true))
b, err := cueyaml.Encode(n)
if err != nil {
return "", err
Expand Down

0 comments on commit 7541204

Please sign in to comment.