feat(ENG-14143): adding colour suppression to the CLI via environment variables - #404
Draft
coillteoir wants to merge 2 commits into
Draft
feat(ENG-14143): adding colour suppression to the CLI via environment variables#404coillteoir wants to merge 2 commits into
coillteoir wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a centralized mechanism for suppressing ANSI color output (and lays groundwork for interactivity suppression) in the Cloudsmith CLI based on environment variables, and wires the color decision into the Click runtime context so existing click.echo/click.secho behavior can follow it.
Changes:
- Adds
ColorMode/TTYModepluscolor_enabled()andis_interactive()helpers incore/utils.py. - Adds a new
coretest module to validate env-var precedence for color and interactivity decisions. - Sets
ctx.colorin the common CLI config decorator based on environment and TTY detection.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
cloudsmith_cli/core/utils.py |
Adds enums and helper functions to determine whether color and interactive prompts should be enabled. |
cloudsmith_cli/core/tests/test_terminal_color.py |
Adds parameterized tests for env-var precedence controlling color/interactivity behavior. |
cloudsmith_cli/cli/decorators.py |
Wires the new color decision into Click’s context (ctx.color) for CLI execution. |
Suppressed comments (2)
cloudsmith_cli/core/tests/test_terminal_color.py:116
- Use consistent American spelling in assertion messages ("color" instead of "colour") to match the repository style guidelines.
assert color_enabled(env, colorMode, ttyMode) == want_color, (
f"colour suppression check failed for environment: {env} wanted {desired}"
)
cloudsmith_cli/core/tests/test_terminal_color.py:121
- In this parametrized test, colorMode is unused; prefixing it with an underscore avoids unused-argument warnings in linters and makes the intent clearer.
def test_no_interactive_environment_variables(
self, env, colorMode, ttyMode, desired
):
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+139
to
+143
| ctx.color = color_enabled( | ||
| dict(os.environ), | ||
| ColorMode.AUTO, | ||
| TTYMode.ENABLED if os.isatty(sys.stdin.fileno()) else TTYMode.DISABLED, | ||
| ) |
Comment on lines
+36
to
+41
| if env.get("NO_COLOR"): | ||
| return False | ||
| if env.get("CLOUDSMITH_FORCE_COLOR") == "true": | ||
| return True | ||
| if env.get("TERM") == "dumb": | ||
| return False |
Comment on lines
+51
to
+60
| def is_interactive(env: dict[str, str], ttyMode: TTYMode) -> bool: | ||
| if env.get("CI") == "true": | ||
| return False | ||
|
|
||
| match ttyMode: | ||
| case TTYMode.ENABLED: | ||
| return True | ||
| case TTYMode.DISABLED: | ||
| return False | ||
| return True |
Comment on lines
+1
to
+25
| from enum import Flag, auto | ||
| from typing import ClassVar | ||
|
|
||
| import pytest | ||
| from _pytest.mark.structures import ParameterSet | ||
|
|
||
| from cloudsmith_cli.core.utils import ( | ||
| ColorMode, | ||
| TTYMode, | ||
| color_enabled, | ||
| is_interactive, | ||
| ) | ||
|
|
||
|
|
||
| class Desired(Flag): | ||
| NONE = 0 | ||
| COLOR = auto() | ||
| INTERACTIVE = auto() | ||
|
|
||
|
|
||
| class TestTerminalUISuppression: | ||
| """Testing precedence in environment varaibles for controlling and overriding terminal | ||
| colours""" | ||
|
|
||
| env_tests: ClassVar[list[ParameterSet]] = [ |
Comment on lines
+26
to
+48
| def color_enabled(env: dict[str, str], colorMode: ColorMode, ttyMode: TTYMode) -> bool: | ||
| """Checks based on environment and""" | ||
| match colorMode: | ||
| case ColorMode.COLOR: | ||
| return True | ||
| case ColorMode.NEVER: | ||
| return False | ||
| case ColorMode.AUTO: | ||
| pass | ||
|
|
||
| if env.get("NO_COLOR"): | ||
| return False | ||
| if env.get("CLOUDSMITH_FORCE_COLOR") == "true": | ||
| return True | ||
| if env.get("TERM") == "dumb": | ||
| return False | ||
|
|
||
| match ttyMode: | ||
| case TTYMode.ENABLED: | ||
| return True | ||
| case TTYMode.DISABLED: | ||
| return False | ||
| return True |
coillteoir
force-pushed
the
pr404
branch
4 times, most recently
from
September 2, 2026 15:30
1a847ec to
45bd2e2
Compare
Adding checks in the CLI to supporess ANSI output and interactive prompts ## ANSI suppression 1. Check for non-empty `NO_COLOUR` flag 2. Check for `CLOUDSMITH_FORCE_COLOR` flag to enable colour 3. Check for TERM=dumb # Prompt suppression 1. Check for CI=true env var 2. Respect shell TTY conditions
… variables feat(ENG-14143): adding colour suppression to the CLI via command line arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.