Coverage for omforme/cli.py: 55.56%

21 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-04 21:04:04 +00:00

1"""CLI interface for single view visualization mapping parameter values to an area scale resembling a (quality) pie.""" 

2 

3import argparse 

4import sys 

5 

6import omforme.omforme as api 

7from omforme import APP_ALIAS, APP_NAME 

8 

9 

10def parse_request(argv: list[str]) -> int | argparse.Namespace: 

11 """DRY.""" 

12 parser = argparse.ArgumentParser( 

13 prog=APP_ALIAS, description=APP_NAME, formatter_class=argparse.RawTextHelpFormatter 

14 ) 

15 parser.add_argument( 

16 '--quiet', 

17 '-q', 

18 dest='quiet', 

19 default=False, 

20 action='store_true', 

21 help='work as quiet as possible (default: False)', 

22 ) 

23 parser.add_argument( 

24 '--verbose', 

25 '-v', 

26 dest='verbose', 

27 default=False, 

28 action='store_true', 

29 help='work logging more information along the way (default: False)', 

30 ) 

31 if not argv: 

32 parser.print_help() 

33 return 0 

34 

35 options = parser.parse_args(argv) 

36 

37 if options.verbose and options.quiet: 

38 parser.error('you cannot be quiet and verbose at the same time') 

39 

40 return options 

41 

42 

43def main(argv: list[str] | None = None) -> int: 

44 """Delegate processing to functional module.""" 

45 argv = sys.argv[1:] if argv is None else argv 

46 options = parse_request(argv) 

47 if isinstance(options, int): 

48 return 0 

49 return api.main(options)