Skip to content

fix: accept the color modes of Helm 4 in --color - #1110

Open
cansentay wants to merge 1 commit into
databus23:masterfrom
cansentay:fix/helm4-color-modes
Open

cansentay wants to merge 1 commit into
databus23:masterfrom
cansentay:fix/helm4-color-modes

Conversation

@cansentay

Copy link
Copy Markdown

Refs #880

Problem

Helm 4 added a global --color flag that takes never, auto or always. Helm parses it from the whole command line before it starts a plugin (newRootCmdWithConfig in pkg/cmd/root.go) and then hands the arguments to the plugin unchanged. With Helm v4.3.2 (helm diff upgrade --dry-run ... rel ./chart):

form master this branch
--color -f values.yaml Helm: invalid color mode "-f": must be one of: never, auto, always same, Helm fails before helm-diff starts
--color=true Helm: invalid color mode "true" same
--color=always Error: invalid argument "always" for "--color" flag: strconv.ParseBool: parsing "always": invalid syntax colored
--color=never, helm --color=never diff upgrade ... Error: invalid argument "never" for "--color" flag: ... not colored
--color=auto Error: invalid argument "auto" for "--color" flag: ... terminal check
bare --color as the last argument colored colored

So on Helm 4 the only way to force colors from the command line was a bare --color at the very end, where Helm ignores its own parse error.

Fix

--color now also takes always, never and auto. A bare --color, --color=true and --color=false behave as before, so nothing changes with Helm 3. auto falls back to the terminal check that runs when no color flag is given. The flag still shows as a switch in --help, so only its usage text changes in the README tables. The README gets a short section on how Helm 4 reads --color.

--color always with a space still fails: --color has to keep working without a value, so the next argument is never read as its value (as with --dry-run=server). The exact command from #880 (--color -f values.yaml) is rejected by Helm itself before helm-diff runs, and Helm 4 does not pass the mode it parsed to plugins in any other way, so that form can only be documented here.

Tests

TestColorFlag runs version with each form of the flag and checks the ansi and bunt color state, plus the error for an unknown value; on master it fails for always, never and auto. go test ./cmd/, make lint and make verify-readme pass. The table was run offline against the plugin built from master and from this branch.

Helm 4 has a global --color flag that takes never, auto or always. It
parses that flag from the whole command line before it starts a plugin,
and hands a --color=<mode> it accepted on to the plugin unchanged.
helm-diff then failed, because its --color only took a bool:

  $ helm diff upgrade --color=always my-release ./chart
  Error: invalid argument "always" for "--color" flag: strconv.ParseBool: parsing "always": invalid syntax

The same happened with Helm's own `helm --color=never diff ...`. A bare
--color followed by another argument never reaches helm-diff on Helm 4:
Helm reads that argument as the mode and rejects it.

Let --color also take always, never and auto. It still works without a
value and with true or false. Document the Helm 4 behaviour in the README.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant