Skip to content

Comments

feat: add --color flag to control ANSI color output#10224

Open
veeceey wants to merge 1 commit intoaquasecurity:mainfrom
veeceey:fix/issue-1091-no-color-option
Open

feat: add --color flag to control ANSI color output#10224
veeceey wants to merge 1 commit intoaquasecurity:mainfrom
veeceey:fix/issue-1091-no-color-option

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 20, 2026

Summary

Adds a global --color flag with three modes: auto (default), never, and always.

  • --color never disables all ANSI color codes in output, useful for CI/CD pipelines and log files
  • --color always forces color output even when not connected to a terminal
  • --color auto (default) preserves existing behavior - colors when outputting to a terminal

The implementation sets color.NoColor from the fatih/color package, 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 - Added ColorFlag definition and wired it into GlobalFlagGroup / GlobalOptions
  • pkg/commands/app.go - Added applyColorSetting() called in PersistentPreRunE before logger init
  • pkg/commands/app_test.go - Tests for applyColorSetting and --color CLI flag validation

Closes #1091

Test plan

  • TestApplyColorSetting verifies color.NoColor is set correctly for never and always
  • TestColorFlag verifies the flag is accepted with valid values and rejected with invalid values
  • All existing tests continue to pass

@veeceey veeceey requested a review from knqyf263 as a code owner February 20, 2026 08:41
@CLAassistant
Copy link

CLAassistant commented Feb 20, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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
@veeceey veeceey force-pushed the fix/issue-1091-no-color-option branch from 4cba8ee to 0f7d5af Compare February 20, 2026 08:42
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.

--no-color option

2 participants