diff --git a/cmd/skaffold/app/cmd/cmd.go b/cmd/skaffold/app/cmd/cmd.go index 2be5da683f9..0b7e2a0217e 100644 --- a/cmd/skaffold/app/cmd/cmd.go +++ b/cmd/skaffold/app/cmd/cmd.go @@ -48,7 +48,7 @@ var ( opts config.SkaffoldOptions v string defaultColor int - forceColors bool + forceColor bool overwrite bool interactive bool timestamps bool @@ -86,7 +86,7 @@ func NewSkaffoldCommand(out, errOut io.Writer) *cobra.Command { // These are used for command completion and send debug messages on stderr. if cmd.Name() != cobra.ShellCompRequestCmd && cmd.Name() != cobra.ShellCompNoDescRequestCmd { instrumentation.SetCommand(cmd.Name()) - out := output.GetWriter(context.Background(), out, defaultColor, forceColors, timestamps) + out := output.GetWriter(context.Background(), out, defaultColor, forceColor, timestamps) cmd.Root().SetOut(out) cmd.Root().SetErr(errOut) @@ -205,7 +205,8 @@ func NewSkaffoldCommand(out, errOut io.Writer) *cobra.Command { templates.ActsAsRootCommand(rootCmd, nil, groups...) rootCmd.PersistentFlags().StringVarP(&v, "verbosity", "v", log.DefaultLogLevel.String(), fmt.Sprintf("Log level: one of %v", log.AllLevels)) rootCmd.PersistentFlags().IntVar(&defaultColor, "color", int(output.DefaultColorCode), "Specify the default output color in ANSI escape codes") - rootCmd.PersistentFlags().BoolVar(&forceColors, "force-colors", false, "Always print color codes (hidden)") + rootCmd.PersistentFlags().BoolVar(&forceColor, "force-colors", false, "Always print color codes (hidden)") + rootCmd.PersistentFlags().BoolVar(&forceColor, "force-color", false, "Always print color codes") rootCmd.PersistentFlags().BoolVar(&interactive, "interactive", true, "Allow user prompts for more information") rootCmd.PersistentFlags().BoolVar(&update.EnableCheck, "update-check", true, "Check for a more recent version of Skaffold") rootCmd.PersistentFlags().BoolVar(×tamps, "timestamps", false, "Print timestamps in logs") @@ -244,6 +245,12 @@ func setEnvVariablesFromFile() { // Each flag can also be set with an env variable whose name starts with `SKAFFOLD_`. func setFlagsFromEnvVariables(rootCmd *cobra.Command) { rootCmd.PersistentFlags().VisitAll(func(f *pflag.Flag) { + if f.Name == "force-color" { + if val, present := os.LookupEnv("FORCE_COLOR"); present { + rootCmd.PersistentFlags().Set(f.Name, val) + } + } + envVar := FlagToEnvVarName(f) if val, present := os.LookupEnv(envVar); present { rootCmd.PersistentFlags().Set(f.Name, val) diff --git a/docs-v2/content/en/docs/references/cli/_index.md b/docs-v2/content/en/docs/references/cli/_index.md index e7287f6c5c6..e25fdde0b3b 100644 --- a/docs-v2/content/en/docs/references/cli/_index.md +++ b/docs-v2/content/en/docs/references/cli/_index.md @@ -1108,6 +1108,7 @@ Env vars: The following options can be passed to any command: --color=34: Specify the default output color in ANSI escape codes + --force-color=false: Always print color codes --interactive=true: Allow user prompts for more information --timestamps=false: Print timestamps in logs --update-check=true: Check for a more recent version of Skaffold @@ -1116,6 +1117,15 @@ The following options can be passed to any command: ``` +Env vars: + +* `SKAFFOLD_COLOR` (same as `--color`) +* `SKAFFOLD_FORCE_COLOR` or `FORCE_COLOR` (same as `--force-color`) +* `SKAFFOLD_INTERACTIVE` (same as `--interactive`) +* `SKAFFOLD_TIMESTAMPS` (same as `--timestamps`) +* `SKAFFOLD_UPDATE_CHECK` (same as `--update-check`) +* `SKAFFOLD_VERBOSITY` (same as `--verbosity`) + ### skaffold render Generate rendered Kubernetes manifests diff --git a/pkg/skaffold/output/color.go b/pkg/skaffold/output/color.go index 8b34388e6d7..5b343c7edbc 100644 --- a/pkg/skaffold/output/color.go +++ b/pkg/skaffold/output/color.go @@ -52,14 +52,14 @@ var DefaultColorCodes = []Color{ } // SetupColors conditionally wraps the input `Writer` with a color enabled `Writer`. -func SetupColors(ctx context.Context, out io.Writer, defaultColor int, forceColors bool) io.Writer { +func SetupColors(ctx context.Context, out io.Writer, defaultColor int, forceColor bool) io.Writer { _, isTerm := term.IsTerminal(out) supportsColor, err := term.SupportsColor(ctx) if err != nil { log.Entry(context.TODO()).Debugf("error checking for color support: %v", err) } - useColors := (isTerm && supportsColor) || forceColors + useColors := (isTerm && supportsColor) || forceColor if useColors { // Use EnableColorsStdout to enable use of color on Windows useColors = false // value is updated if color-enablement is successful diff --git a/pkg/skaffold/output/output.go b/pkg/skaffold/output/output.go index d3a3806a263..76937a80c51 100644 --- a/pkg/skaffold/output/output.go +++ b/pkg/skaffold/output/output.go @@ -63,13 +63,13 @@ func (s skaffoldWriter) Write(p []byte) (int, error) { return written, nil } -func GetWriter(ctx context.Context, out io.Writer, defaultColor int, forceColors bool, timestamps bool) io.Writer { +func GetWriter(ctx context.Context, out io.Writer, defaultColor int, forceColor bool, timestamps bool) io.Writer { if _, isSW := out.(skaffoldWriter); isSW { return out } return skaffoldWriter{ - MainWriter: SetupColors(ctx, out, defaultColor, forceColors), + MainWriter: SetupColors(ctx, out, defaultColor, forceColor), EventWriter: eventV2.NewLogger(constants.DevLoop, "-1"), timestamps: timestamps, }