From d858359acc7435a9f7796120363f9e599b06bb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=BD=B1?= Date: Wed, 29 Jun 2022 16:44:28 +0800 Subject: [PATCH] feat: add log stdin --- cmd/root.go | 5 +++-- cmd/upgrade.go | 9 +++++---- main.go | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 0c71f2d..35aad1e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,6 +1,7 @@ package cmd import ( + "io" "os" "strconv" @@ -30,9 +31,9 @@ The Helm Diff Plugin ` // New creates a new cobra client -func New() *cobra.Command { +func New(out io.Writer) *cobra.Command { - chartCommand := newChartCommand() + chartCommand := newChartCommand(out) cmd := &cobra.Command{ Use: "diff", diff --git a/cmd/upgrade.go b/cmd/upgrade.go index e95403d..988b8e9 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "io" "log" "os" "strings" @@ -78,7 +79,7 @@ perform. var envSettings = cli.New() var yamlSeperator = []byte("\n---\n") -func newChartCommand() *cobra.Command { +func newChartCommand(out io.Writer) *cobra.Command { diff := diffCmd{ namespace: os.Getenv("HELM_NAMESPACE"), } @@ -133,7 +134,7 @@ func newChartCommand() *cobra.Command { diff.release = args[0] diff.chart = args[1] if isHelm3() { - return diff.runHelm3() + return diff.runHelm3(out) } if diff.client == nil { diff.client = createHelmClient() @@ -188,7 +189,7 @@ func newChartCommand() *cobra.Command { } -func (d *diffCmd) runHelm3() error { +func (d *diffCmd) runHelm3(out io.Writer) error { if err := compatibleHelm3Version(); err != nil { return err @@ -262,7 +263,7 @@ func (d *diffCmd) runHelm3() error { } else { newSpecs = manifest.Parse(string(installManifest), d.namespace, d.normalizeManifests, helm3TestHook, helm2TestSuccessHook) } - seenAnyChanges := diff.Manifests(currentSpecs, newSpecs, &d.Options, os.Stdout) + seenAnyChanges := diff.Manifests(currentSpecs, newSpecs, &d.Options, out) if d.detailedExitCode && seenAnyChanges { return Error{ diff --git a/main.go b/main.go index d4ee0de..53905c2 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) func main() { - if err := cmd.New().Execute(); err != nil { + if err := cmd.New(os.Stdout).Execute(); err != nil { switch e := err.(type) { case cmd.Error: os.Exit(e.Code)