From f84ab66ba0208a7cdfb37e6a9aff1b7dcc3fd5c4 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 13 Apr 2022 23:43:12 +0000 Subject: [PATCH] Make --color and --no-color exclusive Signed-off-by: Yusuke Kuoka --- main.go | 8 ++++++++ pkg/app/validate_config.go | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 pkg/app/validate_config.go diff --git a/main.go b/main.go index f9c4a759..058313c2 100644 --- a/main.go +++ b/main.go @@ -952,6 +952,10 @@ func (c configImpl) Color() bool { return c } + if c.NoColor() { + return false + } + // We replicate the helm-diff behavior in helmfile // because when when helmfile calls helm-diff, helm-diff has no access to term and therefore // we can't rely on helm-diff's ability to auto-detect term for color output. @@ -1021,6 +1025,10 @@ func action(do func(*app.App, configImpl) error) func(*cli.Context) error { return err } + if err := app.ValidateConfig(conf); err != nil { + return err + } + a := app.New(conf) if err := do(a, conf); err != nil { diff --git a/pkg/app/validate_config.go b/pkg/app/validate_config.go new file mode 100644 index 00000000..9317435f --- /dev/null +++ b/pkg/app/validate_config.go @@ -0,0 +1,11 @@ +package app + +import "errors" + +func ValidateConfig(conf ApplyConfigProvider) error { + if conf.NoColor() && conf.Color() { + return errors.New("--color and --no-color cannot be specified at the same time") + } + + return nil +}