Skip to content

Commit 85e8b70

Browse files
committed
cmd: use SetIndent(2) to dump yaml subcommands
Signed-off-by: Koichi Shiraishi <[email protected]>
1 parent 263902a commit 85e8b70

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cmd/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"io/ioutil"
6+
"strings"
67

78
"github.com/CircleCI-Public/circleci-cli/api"
89
"github.com/CircleCI-Public/circleci-cli/api/graphql"
@@ -193,11 +194,13 @@ func packConfig(opts configOptions) error {
193194
return errors.Wrap(err, "An error occurred trying to build the tree")
194195
}
195196

196-
y, err := yaml.Marshal(&tree)
197-
if err != nil {
197+
var s strings.Builder
198+
enc := yaml.NewEncoder(&s)
199+
enc.SetIndent(2)
200+
if err := enc.Encode(&tree); err != nil {
198201
return errors.Wrap(err, "Failed trying to marshal the tree to YAML ")
199202
}
200-
fmt.Printf("%s\n", string(y))
203+
fmt.Print(s.String())
201204
return nil
202205
}
203206

cmd/orb.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,12 +1011,14 @@ func packOrb(path string) (string, error) {
10111011
return "", err
10121012
}
10131013

1014-
final, err := yaml.Marshal(&orbSchema)
1015-
if err != nil {
1014+
var s strings.Builder
1015+
enc := yaml.NewEncoder(&s)
1016+
enc.SetIndent(2)
1017+
if err := enc.Encode(&orbSchema); err != nil {
10161018
return "", errors.Wrap(err, "Failed trying to marshal Orb YAML")
10171019
}
10181020

1019-
return string(final), nil
1021+
return s.String(), nil
10201022
}
10211023

10221024
// Travel down a YAML node, replacing values as we go.

0 commit comments

Comments
 (0)