feat(ENG-14143): adding colour suppression to the CLI via environment variables - #404
feat(ENG-14143): adding colour suppression to the CLI via environment variables#404coillteoir wants to merge 2 commits into
Conversation
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.
45bd2e2 to
7831e4a
Compare
97044f2 to
636f550
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
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
cloudsmith_cli/cli/decorators.py:192
ctx.colorcontrols both stdout and stderr, but automatic mode turns only stdout's TTY state into a global Boolean. When stdout is a TTY and stderr is redirected, styled errors therefore leak ANSI into the redirected log; when stdout is piped and stderr is a TTY, terminal errors lose color. In plainAUTOmode, leavectx.colorasNoneso Click detects each destination stream, reserving Boolean overrides for explicit CLI/environment policies.
TTYMode.ENABLED if sys.stdout.isatty() else TTYMode.DISABLED,
| ctx.color = color_enabled( | ||
| dict(os.environ), | ||
| kwargs.pop("color"), | ||
| TTYMode.ENABLED if sys.stdout.isatty() else TTYMode.DISABLED, | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.