1
0
Fork 0

Merging upstream version 0.12.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-10 06:39:52 +01:00
parent f45bc3d463
commit 8d2f70e3c7
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
77 changed files with 23610 additions and 2331 deletions

View file

@ -8,23 +8,27 @@ Extension for the python ``click`` module
to provide a group or command with aliases.
"""
import logging
from typing import Any
import click
from rich import pretty
from rich.logging import RichHandler
from rich.console import Console
class AliasedGroup(click.Group):
"""
Implements a subclass of Group that accepts a prefix for a command.
If there were a command called push, it would accept pus as an alias (so long as it was unique)
"""
def get_command(self, ctx: click.Context, cmd_name: str) -> Any:
"""Documentation to build"""
rv = click.Group.get_command(self, ctx, cmd_name)
if rv is not None:
return rv
matches = [x for x in self.list_commands(ctx)
if x.startswith(cmd_name)]
matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)]
if not matches:
return None
if len(matches) == 1:
@ -36,3 +40,45 @@ class AliasedGroup(click.Group):
# always return the full command name
_, cmd, args = super().resolve_command(ctx, args)
return cmd.name, cmd, args
def cli_logging(level: str = "error") -> logging.Logger:
"""
Configures and returns a logger with the specified logging level.
This function sets up the logging configuration using the RichHandler
to provide rich formatted log messages. The log messages will include
the time and can contain markup and rich tracebacks.
Args:
level (str): The logging level as a string (e.g., 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL').
Returns:
logging.Logger: A configured logger instance.
"""
FORMAT = "%(message)s"
logging.basicConfig(
level=level.upper(),
format=FORMAT,
datefmt="[%X]",
handlers=[
RichHandler(
show_path=True,
show_time=True,
show_level=True,
markup=True,
rich_tracebacks=True,
tracebacks_suppress=[click],
)
],
)
log = logging.getLogger("rich")
return log
def console_configuration() -> Console:
"""Configure Rich Terminal for the CLI."""
pretty.install()
console = Console()
return console