Skip to content

feat(ENG-14143): adding colour suppression to the CLI via environment variables - #404

Open
coillteoir wants to merge 2 commits into
masterfrom
pr404
Open

feat(ENG-14143): adding colour suppression to the CLI via environment variables#404
coillteoir wants to merge 2 commits into
masterfrom
pr404

Conversation

@coillteoir

@coillteoir coillteoir commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@coillteoir
coillteoir requested a review from a team as a code owner September 2, 2026 14:36
Copilot AI lite review requested due to automatic review settings September 2, 2026 14:36
@coillteoir
coillteoir marked this pull request as draft September 2, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/TTYMode plus color_enabled() and is_interactive() helpers in core/utils.py.
  • Adds a new core test module to validate env-var precedence for color and interactivity decisions.
  • Sets ctx.color in 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 thread cloudsmith_cli/cli/decorators.py Outdated
Comment thread cloudsmith_cli/core/utils.py
Comment thread cloudsmith_cli/core/utils.py Outdated
Comment thread cloudsmith_cli/core/tests/test_terminal_color.py Outdated
Comment thread cloudsmith_cli/core/utils.py
@coillteoir
coillteoir force-pushed the pr404 branch 5 times, most recently from 45bd2e2 to 7831e4a Compare September 2, 2026 15:45
@coillteoir
coillteoir marked this pull request as ready for review September 3, 2026 13:24
@coillteoir
coillteoir force-pushed the pr404 branch 2 times, most recently from 97044f2 to 636f550 Compare September 3, 2026 13:31
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.color controls 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 plain AUTO mode, leave ctx.color as None so Click detects each destination stream, reserving Boolean overrides for explicit CLI/environment policies.
            TTYMode.ENABLED if sys.stdout.isatty() else TTYMode.DISABLED,

Comment on lines +189 to +193
ctx.color = color_enabled(
dict(os.environ),
kwargs.pop("color"),
TTYMode.ENABLED if sys.stdout.isatty() else TTYMode.DISABLED,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants