Skip to content

Commit 916891f

Browse files
authored
--color or HELM_DIFF_COLOR=true to force color (#343)
Resolves #344
1 parent c168437 commit 916891f

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

README.md

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The Helm Diff Plugin
6767
6868
* Shows a diff explaining what a helm rollback would change:
6969
This fetches the currently deployed version of a release
70-
and compares it to the previously deployed versions of the release, that you
70+
and compares it to the previously deployed version of the release, that you
7171
want to rollback. This can be used visualize what changes a
7272
helm rollback will perform.
7373
@@ -83,15 +83,37 @@ Available Commands:
8383
version Show version of the helm diff plugin
8484
8585
Flags:
86-
-h, --help help for diff
87-
--no-color remove colors from the output
88-
--reset-values reset the values to the ones built into the chart and merge in any new values
89-
--reuse-values reuse the last release's values and merge in any new values
90-
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
91-
--suppress stringArray allows suppression of the values listed in the diff output
92-
-q, --suppress-secrets suppress secrets in the output
93-
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
94-
--version string specify the exact chart version to use. If this is not specified, the latest version is used
86+
--allow-unreleased enables diffing of releases that are not yet deployed via Helm
87+
-a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions
88+
--color color output. You can control the value for this flag via HELM_DIFF_COLOR=[true|false]. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb"
89+
-C, --context int output NUM lines of context around changes (default -1)
90+
--detailed-exitcode return a non-zero exit code when there are changes
91+
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
92+
--disable-openapi-validation disables rendered templates validation against the Kubernetes OpenAPI Schema
93+
--disable-validation disables rendered templates validation against the Kubernetes cluster you are currently pointing to. This is the same validation performed on an install
94+
--dry-run disables cluster access and show diff as if it was install. Implies --install, --reset-values, and --disable-validation
95+
-h, --help help for diff
96+
--include-tests enable the diffing of the helm test hooks
97+
--install enables diffing of releases that are not yet deployed via Helm (equivalent to --allow-unreleased, added to match "helm upgrade --install" command
98+
--kubeconfig string This flag is ignored, to allow passing of this top level flag to helm
99+
--no-color remove colors from the output. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not "dumb"
100+
--no-hooks disable diffing of hooks
101+
--normalize-manifests normalize manifests before running diff to exclude style differences from the output
102+
--output string Possible values: diff, simple, json, template. When set to "template", use the env var HELM_DIFF_TPL to specify the template. (default "diff")
103+
--post-renderer string the path to an executable to be used for post rendering. If it exists in $PATH, the binary will be used, otherwise it will try to look for the executable at the given path
104+
--repo string specify the chart repository url to locate the requested chart
105+
--reset-values reset the values to the ones built into the chart and merge in any new values
106+
--reuse-values reuse the last release's values and merge in any new values. If '--reset-values' is specified, this is ignored
107+
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
108+
--set-file stringArray set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)
109+
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
110+
--show-secrets do not redact secret values in the output
111+
--strip-trailing-cr strip trailing carriage return on input
112+
--suppress stringArray allows suppression of the values listed in the diff output
113+
-q, --suppress-secrets suppress secrets in the output
114+
--three-way-merge use three-way-merge to compute patch and generate diff output
115+
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
116+
--version string specify the exact chart version to use. If this is not specified, the latest version is used
95117
96118
Additional help topics:
97119
diff

cmd/root.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"os"
5+
"strconv"
56

67
"github.com/mgutz/ansi"
78
"github.com/spf13/cobra"
@@ -41,9 +42,23 @@ func New() *cobra.Command {
4142
Args: chartCommand.Args,
4243
// parse the flags and check for actions like suppress-secrets, no-colors
4344
PersistentPreRun: func(cmd *cobra.Command, args []string) {
44-
if nc, _ := cmd.Flags().GetBool("no-color"); nc {
45+
var fc *bool
46+
47+
if cmd.Flags().Changed("color") {
48+
v, _ := cmd.Flags().GetBool("color")
49+
fc = &v
50+
} else {
51+
v, err := strconv.ParseBool(os.Getenv("HELM_DIFF_COLOR"))
52+
if err == nil {
53+
fc = &v
54+
}
55+
}
56+
57+
nc, _ := cmd.Flags().GetBool("no-color")
58+
59+
if nc || (fc != nil && !*fc) {
4560
ansi.DisableColors(true)
46-
} else if !cmd.Flags().Changed("no-color") {
61+
} else if !cmd.Flags().Changed("no-color") && fc == nil {
4762
term := terminal.IsTerminal(int(os.Stdout.Fd()))
4863
// https://github.com/databus23/helm-diff/issues/281
4964
dumb := os.Getenv("TERM") == "dumb"
@@ -57,7 +72,8 @@ func New() *cobra.Command {
5772
}
5873

5974
// add no-color as global flag
60-
cmd.PersistentFlags().Bool("no-color", false, "remove colors from the output")
75+
cmd.PersistentFlags().Bool("no-color", false, "remove colors from the output. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not \"dumb\"")
76+
cmd.PersistentFlags().Bool("color", false, "color output. You can control the value for this flag via HELM_DIFF_COLOR=[true|false]. If both --no-color and --color are unspecified, coloring enabled only when the stdout is a term and TERM is not \"dumb\"")
6177
// add flagset from chartCommand
6278
cmd.Flags().AddFlagSet(chartCommand.Flags())
6379
cmd.AddCommand(newVersionCmd(), chartCommand)

0 commit comments

Comments
 (0)