feat(RHOAIENG-54609): add --no-color flag and centralized color package#54
Conversation
📝 WalkthroughWalkthroughThis PR adds a Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes IssuesPotential data race in The assignment Undocumented behavior in The new helper functions ( Missing validation in flag integration No validation ensures 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4c4f493 to
374d524
Compare
Description
Add
--no-colorflag to thelintcommand with automatic color detection following the NO_COLOR standard.Color is disabled automatically with the following priority chain:
NoColor=trueto prevent ANSI codes from corrupting machine-readable output--no-colorflag explicitly disables color when setNO_COLORenvironment variable disables color when set to any non-empty valueAdditionally, this PR refactors color formatting by extracting inline
color.New(...)calls fromoutput_table.gointo a centralizedpkg/util/color/symbols.gopackage. This ensures symbols and severity labels are generated at render time (respecting thecolor.NoColorglobal), rather than at init time when the color state is not yet determined.Changes
pkg/lint/command.go: Add--no-colorflag registration, color detection logic inComplete(), andIsTerminal()method usinggolang.org/x/termpkg/lint/command_options.go: AddNoColorfield toSharedOptions, addWithOutputFormatandWithIOfunctional optionspkg/lint/constants.go: AddflagDescNoColorconstantpkg/lint/output_table.go: Replace inline color symbols with centralizedutilcolorpackage callspkg/util/color/symbols.go: New package providing status symbols, severity labels, and verdict strings as functionsgo.mod: Promotegolang.org/x/termfrom indirect to direct dependencyJIRA ISSUE
RHOAIENG-54609
How Has This Been Tested?
Unit tests:
TestCommand_AddFlagsto verify--no-colorflag registrationManual testing against a live OpenShift cluster with odh-operator installed
./bin/kubectl-odh lint --target-version 3.0.0-- colors rendered on TTY./bin/kubectl-odh lint --target-version 3.0.0 --no-color-- colors strippedNO_COLOR=1 ./bin/kubectl-odh lint --target-version 3.0.0-- colors stripped via env varunset NO_COLOR && ./bin/kubectl-odh lint --target-version 3.0.0-- colors restored./bin/kubectl-odh lint --target-version 3.0.0 -o json-- no ANSI codes in JSON outputmake lint-- 0 issuesmake build-- builds successfullyWithout no color flag
With no color flag
with NO_COLOR env set
Merge criteria:
Summary by CodeRabbit
Release Notes
New Features
--no-colorCLI flag to disable colored output in lint results. The flag respects theNO_COLORenvironment variable and is automatically enabled for JSON and YAML structured output formats.Refactor