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

1"""Output format of the command result.""" 

2from __future__ import annotations 

3 

4from enum import Enum 

5 

6from ..logs import logger 

7 

8 

9class OutputFormat(Enum): 

10 """Output format of the command result.""" 

11 

12 TABLE = "table" 

13 JSON = "json" 

14 # others...? 

15 

16 

17# TODO: consolidate this metadata with the enum 

18 

19OUTPUTFORMAT_REPR = { 

20 OutputFormat.TABLE: "table", 

21 OutputFormat.JSON: "JSON", 

22} 

23 

24OUTPUTFORMAT_EMOJI = { 

25 OutputFormat.TABLE: ":page_facing_up:", 

26 OutputFormat.JSON: ":package:", 

27} 

28 

29 

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 

37 

38 

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