-
Notifications
You must be signed in to change notification settings - Fork 74
feat(cli): add --[no-]color flag to control output colorization #1030
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
Conversation
Adds a --force-color flag that accepts color levels 1, 2, or 3 to force colored output even when stdout is not a TTY. Also fixes the existing --no-color flag which wasn't being used due to color handling happening at module load time before argument parsing. Closes aws/aws-cdk#12270
|
Hey, appreciate the fix! Semantically, the cli options should be this: We don't currently use color levels, so I am not very keen to introduce them as an external option. |
mrgrain
left a comment
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.
see comment
Replace --force-color [1|2|3] with a simple --color boolean flag per maintainer feedback. When --color is passed, truecolor output is enabled.
Head branch was pushed to by a user without write access
|
Simplified to just |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1030 +/- ##
==========================================
+ Coverage 87.69% 87.71% +0.01%
==========================================
Files 72 72
Lines 10095 10102 +7
Branches 1332 1335 +3
==========================================
+ Hits 8853 8861 +8
+ Misses 1217 1216 -1
Partials 25 25
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This addresses issue #1031.
When calling the CDK CLI programmatically (e.g., from a subprocess), colors are automatically disabled because stdout isn't a TTY. This makes it difficult to capture colored output for tools that want to preserve formatting.
I've added a
--colorflag to indicate color output is desired. The--no-colorflag takes priority if both are specified.I also fixed a subtle bug where the existing
--no-colorflag wasn't actually being used - the color disabling was happening at module load time before arguments were even parsed. Now both flags work correctly and respect the priority order:--no-color>--color>TTYdetection.Tested locally and added unit tests covering all the new behavior.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license