Coverage for lintro / enums / output_format.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Output format enum definitions. 

2 

3This module defines the supported output formats for displaying results. 

4""" 

5 

6from __future__ import annotations 

7 

8from enum import StrEnum, auto 

9 

10from loguru import logger 

11 

12 

13class OutputFormat(StrEnum): 

14 """Supported output formats for rendering results. 

15 

16 Values are lower-case string identifiers to align with CLI choices. 

17 """ 

18 

19 PLAIN = auto() 

20 GRID = auto() 

21 MARKDOWN = auto() 

22 HTML = auto() 

23 JSON = auto() 

24 CSV = auto() 

25 GITHUB = auto() 

26 SARIF = auto() 

27 

28 

29def normalize_output_format(value: str | OutputFormat) -> OutputFormat: 

30 """Normalize a raw value to an OutputFormat enum. 

31 

32 Args: 

33 value: str or OutputFormat to normalize. 

34 

35 Returns: 

36 OutputFormat: Normalized enum value. 

37 """ 

38 if isinstance(value, OutputFormat): 

39 return value 

40 try: 

41 return OutputFormat[value.upper()] 

42 except (KeyError, AttributeError) as e: 

43 logger.debug(f"Invalid OutputFormat value '{value}': {e}. Defaulting to GRID.") 

44 return OutputFormat.GRID