Coverage for .tox/coverage/lib/python3.11/site-packages/wuttjamaican/cli/problems.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-12-29 13:06 -0600

1# -*- coding: utf-8; -*- 

2################################################################################ 

3# 

4# WuttJamaican -- Base package for Wutta Framework 

5# Copyright © 2023-2025 Lance Edgar 

6# 

7# This file is part of Wutta Framework. 

8# 

9# Wutta Framework is free software: you can redistribute it and/or modify it 

10# under the terms of the GNU General Public License as published by the Free 

11# Software Foundation, either version 3 of the License, or (at your option) any 

12# later version. 

13# 

14# Wutta Framework is distributed in the hope that it will be useful, but 

15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

16# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 

17# more details. 

18# 

19# You should have received a copy of the GNU General Public License along with 

20# Wutta Framework. If not, see <http://www.gnu.org/licenses/>. 

21# 

22################################################################################ 

23""" 

24See also: :ref:`wutta-problems` 

25""" 

26 

27import sys 

28from typing import List 

29 

30import rich 

31import typer 

32from typing_extensions import Annotated 

33 

34from .base import wutta_typer 

35 

36 

37@wutta_typer.command() 

38def problems( 

39 ctx: typer.Context, 

40 systems: Annotated[ 

41 List[str], 

42 typer.Option( 

43 "--system", 

44 "-s", 

45 help="System for which to perform checks; can be specified more " 

46 "than once. If not specified, all systems are assumed.", 

47 ), 

48 ] = None, 

49 problems: Annotated[ # pylint: disable=redefined-outer-name 

50 List[str], 

51 typer.Option( 

52 "--problem", 

53 "-p", 

54 help="Identify a particular problem check; can be specified " 

55 "more than once. If not specified, all checks are assumed.", 

56 ), 

57 ] = None, 

58 list_checks: Annotated[ 

59 bool, 

60 typer.Option( 

61 "--list", 

62 "-l", 

63 help="List available problem checks; optionally filtered " 

64 "per --system and --problem", 

65 ), 

66 ] = False, 

67): 

68 """ 

69 Find and report on problems with the data or system 

70 """ 

71 config = ctx.parent.wutta_config 

72 app = config.get_app() 

73 handler = app.get_problem_handler() 

74 

75 # try to warn user if unknown system is specified; but otherwise ignore 

76 supported = handler.get_supported_systems() 

77 for key in systems or []: 

78 if key not in supported: 

79 rich.print( 

80 f"\n[bold yellow]No problem reports exist for system: {key}[/bold yellow]" 

81 ) 

82 

83 checks = handler.filter_problem_checks(systems=systems, problems=problems) 

84 

85 if list_checks: 

86 

87 count = 0 

88 organized = handler.organize_problem_checks(checks) 

89 for system in sorted(organized): 

90 rich.print(f"\n[bold]{system}[/bold]") 

91 sys.stdout.write("-------------------------\n") 

92 for problem in sorted(organized[system]): 

93 sys.stdout.write(f"{problem}\n") 

94 count += 1 

95 

96 sys.stdout.write("\n") 

97 sys.stdout.write(f"found {count} problem checks\n") 

98 

99 else: 

100 handler.run_problem_checks(checks)