Skip to content

Conversation

@AndyBodnar
Copy link
Contributor

@AndyBodnar AndyBodnar commented Jan 19, 2026

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 --color flag to indicate color output is desired. The --no-color flag takes priority if both are specified.

I also fixed a subtle bug where the existing --no-color flag 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 > TTY detection.

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

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
@mrgrain
Copy link
Contributor

mrgrain commented Jan 19, 2026

Hey, appreciate the fix! Semantically, the cli options should be this:

[no option provide] - automatic detection
--color - always show color
--no-color - never show color

We don't currently use color levels, so I am not very keen to introduce them as an external option.

Copy link
Contributor

@mrgrain mrgrain left a 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.
auto-merge was automatically disabled January 22, 2026 01:10

Head branch was pushed to by a user without write access

@AndyBodnar
Copy link
Contributor Author

Simplified to just --color as a boolean. When passed it forces truecolor output, otherwise auto-detection kicks in as usual. Also kept the fix for --no-color not being respected at module load time.

@rix0rrr rix0rrr changed the title feat(cli): add --force-color flag to enforce colored output feat(cli): add --[no-]color flag to control output colorization Jan 22, 2026
@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.71%. Comparing base (e966a35) to head (dcd3743).

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              
Flag Coverage Δ
suite.unit 87.71% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mrgrain mrgrain self-requested a review January 23, 2026 14:24
@mrgrain mrgrain dismissed their stale review January 23, 2026 14:24

rico approved

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mrgrain mrgrain added this pull request to the merge queue Jan 23, 2026
Merged via the queue into aws:main with commit 91be9f1 Jan 23, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants