Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--color or HELM_DIFF_COLOR=true to force color #343

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 32 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The Helm Diff Plugin

* Shows a diff explaining what a helm rollback would change:
This fetches the currently deployed version of a release
and compares it to the previously deployed versions of the release, that you
and compares it to the previously deployed version of the release, that you
want to rollback. This can be used visualize what changes a
helm rollback will perform.

Expand All @@ -83,15 +83,37 @@ Available Commands:
version Show version of the helm diff plugin

Flags:
-h, --help help for diff
--no-color remove colors from the output
--reset-values reset the values to the ones built into the chart and merge in any new values
--reuse-values reuse the last release's values and merge in any new values
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--suppress stringArray allows suppression of the values listed in the diff output
-q, --suppress-secrets suppress secrets in the output
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
--version string specify the exact chart version to use. If this is not specified, the latest version is used
--allow-unreleased enables diffing of releases that are not yet deployed via Helm
-a, --api-versions stringArray Kubernetes api versions used for Capabilities.APIVersions
--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"
-C, --context int output NUM lines of context around changes (default -1)
--detailed-exitcode return a non-zero exit code when there are changes
--devel use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
--disable-openapi-validation disables rendered templates validation against the Kubernetes OpenAPI Schema
--disable-validation disables rendered templates validation against the Kubernetes cluster you are currently pointing to. This is the same validation performed on an install
--dry-run disables cluster access and show diff as if it was install. Implies --install, --reset-values, and --disable-validation
-h, --help help for diff
--include-tests enable the diffing of the helm test hooks
--install enables diffing of releases that are not yet deployed via Helm (equivalent to --allow-unreleased, added to match "helm upgrade --install" command
--kubeconfig string This flag is ignored, to allow passing of this top level flag to helm
--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"
--no-hooks disable diffing of hooks
--normalize-manifests normalize manifests before running diff to exclude style differences from the output
--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")
--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
--repo string specify the chart repository url to locate the requested chart
--reset-values reset the values to the ones built into the chart and merge in any new values
--reuse-values reuse the last release's values and merge in any new values. If '--reset-values' is specified, this is ignored
--set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--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)
--set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--show-secrets do not redact secret values in the output
--strip-trailing-cr strip trailing carriage return on input
--suppress stringArray allows suppression of the values listed in the diff output
-q, --suppress-secrets suppress secrets in the output
--three-way-merge use three-way-merge to compute patch and generate diff output
-f, --values valueFiles specify values in a YAML file (can specify multiple) (default [])
--version string specify the exact chart version to use. If this is not specified, the latest version is used

Additional help topics:
diff
Expand Down
22 changes: 19 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"strconv"

"github.com/mgutz/ansi"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -41,9 +42,23 @@ func New() *cobra.Command {
Args: chartCommand.Args,
// parse the flags and check for actions like suppress-secrets, no-colors
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if nc, _ := cmd.Flags().GetBool("no-color"); nc {
var fc *bool

if cmd.Flags().Changed("color") {
v, _ := cmd.Flags().GetBool("color")
fc = &v
} else {
v, err := strconv.ParseBool(os.Getenv("HELM_DIFF_COLOR"))
if err == nil {
fc = &v
}
}

nc, _ := cmd.Flags().GetBool("no-color")

if nc || (fc != nil && !*fc) {
ansi.DisableColors(true)
} else if !cmd.Flags().Changed("no-color") {
} else if !cmd.Flags().Changed("no-color") && fc == nil {
term := terminal.IsTerminal(int(os.Stdout.Fd()))
// https://github.com/databus23/helm-diff/issues/281
dumb := os.Getenv("TERM") == "dumb"
Expand All @@ -57,7 +72,8 @@ func New() *cobra.Command {
}

// add no-color as global flag
cmd.PersistentFlags().Bool("no-color", false, "remove colors from the output")
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\"")
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\"")
// add flagset from chartCommand
cmd.Flags().AddFlagSet(chartCommand.Flags())
cmd.AddCommand(newVersionCmd(), chartCommand)
Expand Down