Skip to content

Conversation

@AndyBodnar
Copy link

@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 --force-color flag that accepts a color level (1 for 16 colors, 2 for 256 colors, 3 for 16 million colors). If you pass --force-color without a value, it defaults to level 1. 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 > --force-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

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.

2 participants