1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-18 00:48:06 +00:00
thatmattlove-hyperglass/hyperglass/cli/echo.py
Jason Hall 830f300822 Upgraded tooling and testing
Due to changes in tooling from the originals used file formats have changed.

pnpm	10.10.0
rye	0.44.0
ruff	0.11.8

CI is now testing on a matrix of pnpm, node, and python versions. This
will hopefully cover edgecases where users are running various version.
Still needs update to use python version in matrix with `rye`.

Installs OS deps in workflow

Adds 'packages' key in workspace form pnpm 9

Makes testing for BaseExternal configurable

Adds redis and httpbin as service containers

ruff lint changed dictionary comprehensions

adds environment variables for httpbin

Fixes runner to docker communications
2025-05-13 17:55:56 -04:00

43 lines
1.4 KiB
Python

"""Helper functions for CLI message printing."""
# Standard Library
import typing as t
# Project
from hyperglass.log import HyperglassConsole
class Echo:
"""Container for console-printing functions."""
_console = HyperglassConsole
def _fmt(self, message: t.Any, *args: t.Any, **kwargs: t.Any) -> t.Any:
if isinstance(message, str):
args = (f"[bold]{arg}[/bold]" for arg in args)
kwargs = {k: f"[bold]{v}[/bold]" for k, v in kwargs.items()}
return message.format(*args, **kwargs)
return message
def error(self, message: str, *args, **kwargs):
"""Print an error message."""
return self._console.print(self._fmt(message, *args, **kwargs), style="error")
def info(self, message: str, *args, **kwargs):
"""Print an informational message."""
return self._console.print(self._fmt(message, *args, **kwargs), style="info")
def warning(self, message: str, *args, **kwargs):
"""Print a warning message."""
return self._console.print(self._fmt(message, *args, **kwargs), style="info")
def success(self, message: str, *args, **kwargs):
"""Print a success message."""
return self._console.print(self._fmt(message, *args, **kwargs), style="success")
def plain(self, message: str, *args, **kwargs):
"""Print an unformatted message."""
return self._console.print(self._fmt(message, *args, **kwargs))
echo = Echo()