Skip to content

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

Draft
coillteoir wants to merge 2 commits into
masterfrom
pr404
Draft

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 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
coillteoir force-pushed the pr404 branch 4 times, most recently from 1a847ec to 45bd2e2 Compare September 2, 2026 15:30
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
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