From 85e8b7082167f0f5594c7d24530ee1fb60ec817b Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Sat, 19 Mar 2022 05:56:51 +0900 Subject: [PATCH] cmd: use SetIndent(2) to dump yaml subcommands Signed-off-by: Koichi Shiraishi --- cmd/config.go | 9 ++++++--- cmd/orb.go | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index b293ff787..416013b56 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "io/ioutil" + "strings" "github.com/CircleCI-Public/circleci-cli/api" "github.com/CircleCI-Public/circleci-cli/api/graphql" @@ -193,11 +194,13 @@ func packConfig(opts configOptions) error { return errors.Wrap(err, "An error occurred trying to build the tree") } - y, err := yaml.Marshal(&tree) - if err != nil { + var s strings.Builder + enc := yaml.NewEncoder(&s) + enc.SetIndent(2) + if err := enc.Encode(&tree); err != nil { return errors.Wrap(err, "Failed trying to marshal the tree to YAML ") } - fmt.Printf("%s\n", string(y)) + fmt.Print(s.String()) return nil } diff --git a/cmd/orb.go b/cmd/orb.go index 11cfef643..475828b4a 100644 --- a/cmd/orb.go +++ b/cmd/orb.go @@ -1011,12 +1011,14 @@ func packOrb(path string) (string, error) { return "", err } - final, err := yaml.Marshal(&orbSchema) - if err != nil { + var s strings.Builder + enc := yaml.NewEncoder(&s) + enc.SetIndent(2) + if err := enc.Encode(&orbSchema); err != nil { return "", errors.Wrap(err, "Failed trying to marshal Orb YAML") } - return string(final), nil + return s.String(), nil } // Travel down a YAML node, replacing values as we go.