feat: add --color flag to control ANSI color output#10224
Open
veeceey wants to merge 1 commit intoaquasecurity:mainfrom
Open
feat: add --color flag to control ANSI color output#10224veeceey wants to merge 1 commit intoaquasecurity:mainfrom
veeceey wants to merge 1 commit intoaquasecurity:mainfrom
Conversation
|
|
Add a global --color flag with three modes: auto (default), never, and always. This allows users to force-disable colors for CI/log files or force-enable them in environments where auto-detection fails. The flag sets color.NoColor from the fatih/color package, which controls color output globally for both log messages and table output. Closes aquasecurity#1091
4cba8ee to
0f7d5af
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a global
--colorflag with three modes:auto(default),never, andalways.--color neverdisables all ANSI color codes in output, useful for CI/CD pipelines and log files--color alwaysforces color output even when not connected to a terminal--color auto(default) preserves existing behavior - colors when outputting to a terminalThe implementation sets
color.NoColorfrom thefatih/colorpackage, which is used throughout trivy for both log-level colorization and table output severity highlighting.Also supports config file (
color: never) and env var (TRIVY_COLOR=never).Files changed
pkg/flag/global_flags.go- AddedColorFlagdefinition and wired it intoGlobalFlagGroup/GlobalOptionspkg/commands/app.go- AddedapplyColorSetting()called inPersistentPreRunEbefore logger initpkg/commands/app_test.go- Tests forapplyColorSettingand--colorCLI flag validationCloses #1091
Test plan
TestApplyColorSettingverifiescolor.NoColoris set correctly forneverandalwaysTestColorFlagverifies the flag is accepted with valid values and rejected with invalid values