From 6ab6e13576efd670871aea30b69b10081339c544 Mon Sep 17 00:00:00 2001 From: Justin Scott Date: Mon, 19 Jun 2017 12:57:17 -0700 Subject: [PATCH] Update init output to print pretty JSON. --- cmd/helm/init.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/helm/init.go b/cmd/helm/init.go index d6270402e..2982e95d2 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -17,6 +17,8 @@ limitations under the License. package main import ( + "bytes" + "encoding/json" "errors" "fmt" "io" @@ -196,14 +198,20 @@ func (i *initCmd) run() error { } switch i.opts.Output.String() { case "json": + var out bytes.Buffer jsonb, err := yaml.ToJSON([]byte(body)) - if err != nil { + if err := json.Indent(&out, jsonb, "", " "); err != nil { + return err + } + tm := []byte("{\"apiVersion\":\"extensions/v1beta1\",\"kind\":\"Deployment\",") + j := append(tm, jsonb[1:]...) + if err := json.Indent(&out, j, "", " "); err != nil { return err } - io.WriteString(i.out, "{\"apiVersion\":\"extensions/v1beta1\",\"kind\":\"Deployment\",") - if _, err = i.out.Write(jsonb[1:]); err != nil { + if _, err = i.out.Write(out.Bytes()); err != nil { return err } + return nil case "yaml": if err := writeYAMLManifest("extensions/v1beta1", "Deployment", body, true, false); err != nil {