Coverage for harbor_cli/output/format.py: 42%
20 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-30 13:01 +0100
« prev ^ index » next coverage.py v6.5.0, created at 2023-01-30 13:01 +0100
1"""Output format of the command result."""
2from __future__ import annotations
4from enum import Enum
6from ..logs import logger
9class OutputFormat(Enum):
10 """Output format of the command result."""
12 TABLE = "table"
13 JSON = "json"
14 # others...?
17# TODO: consolidate this metadata with the enum
19OUTPUTFORMAT_REPR = {
20 OutputFormat.TABLE: "table",
21 OutputFormat.JSON: "JSON",
22}
24OUTPUTFORMAT_EMOJI = {
25 OutputFormat.TABLE: ":page_facing_up:",
26 OutputFormat.JSON: ":package:",
27}
30def output_format_repr(fmt: OutputFormat) -> str:
31 """Return a human-readable representation of an output format."""
32 f = OUTPUTFORMAT_REPR.get(fmt)
33 if f is None:
34 logger.warning(f"Unknown output format: {fmt}")
35 f = "Unknown"
36 return f
39def output_format_emoji(fmt: OutputFormat) -> str:
40 """Return an emoji for an output format."""
41 f = OUTPUTFORMAT_EMOJI.get(fmt)
42 if f is None:
43 logger.warning(f"Unknown output format: {fmt}")
44 f = ":question:"
45 return f