-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: support FORCE_COLOR
env variable
#9274
Open
omus
wants to merge
3
commits into
GoogleContainerTools:main
Choose a base branch
from
omus:cv/force-color-env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+24
−7
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The flag is being initialized twice, in line 208 and 209. |
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way I should deprecate this option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the name of the flag is a breaking change, we shouldn't do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can keep both
--force-colors
and--force-color
as flags to avoid any breakage. How does Skaffold deal with informing users about upcoming breaking changes?