Coverage for harbor_cli/format.py: 42%
20 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
1"""Output format of command results.
3Not a part of the output module to avoid circular imports caused by the
4instantiation of the global state object, which imports other modules
5that rely on output formats."""
6from __future__ import annotations
8from enum import Enum
10from .logs import logger
13class OutputFormat(Enum):
14 """Output format of the command result."""
16 TABLE = "table"
17 JSON = "json"
18 # others...?
21# TODO: consolidate this metadata with the enum
23OUTPUTFORMAT_REPR = {
24 OutputFormat.TABLE: "table",
25 OutputFormat.JSON: "JSON",
26}
28OUTPUTFORMAT_EMOJI = {
29 OutputFormat.TABLE: ":page_facing_up:",
30 OutputFormat.JSON: ":package:",
31}
34def output_format_repr(fmt: OutputFormat) -> str:
35 """Return a human-readable representation of an output format."""
36 f = OUTPUTFORMAT_REPR.get(fmt)
37 if f is None:
38 logger.warning(f"Unknown output format: {fmt}")
39 f = "Unknown"
40 return f
43def output_format_emoji(fmt: OutputFormat) -> str:
44 """Return an emoji for an output format."""
45 f = OUTPUTFORMAT_EMOJI.get(fmt)
46 if f is None:
47 logger.warning(f"Unknown output format: {fmt}")
48 f = ":question:"
49 return f