Skip to content

Commit

Permalink
cmd: use SetIndent(2) to dump yaml subcommands
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <[email protected]>
  • Loading branch information
zchee committed Mar 18, 2022
1 parent 263902a commit 85e8b70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 85e8b70

Please sign in to comment.