Coverage for harbor_cli/output/console.py: 60%
18 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-09 12:09 +0100
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-09 12:09 +0100
1from __future__ import annotations
3from typing import Any
4from typing import NoReturn
5from typing import Optional
7from rich.console import Console
9from ..logs import logger
11_exit = exit # save the original exit function
13console = Console()
14err_console = Console(
15 stderr=True,
16 style="red",
17 highlight=False,
18 soft_wrap=True,
19)
22def success(msg: str) -> None:
23 """Prints a message to the default console.
25 Parameters
26 ----------
27 msg : str
28 Message to print.
29 """
30 console.print(msg, style="green")
33def exit(msg: Optional[str] = None, code: int = 0) -> NoReturn:
34 """Prints a message to the default console and exits with the given
35 code (default: 0).
37 Parameters
38 ----------
39 msg : str
40 Message to print.
41 code : int, optional
42 Exit code, by default 0
43 """
44 if msg:
45 logger.info(msg)
46 raise SystemExit(code)
49def exit_err(msg: str, code: int = 1, prefix: str = "ERROR", **extra: Any) -> NoReturn:
50 """Prints a message to the error console and exits with the given
51 code (default: 1).
53 Parameters
54 ----------
55 msg : str
56 Message to print.
57 code : int, optional
58 Exit code, by default 1
59 """
60 logger.bind(**extra).error(msg)
61 raise SystemExit(code)