Coverage for src/aquasense/common/arghelp.py: 0%

14 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2026-04-20 10:23 +0000

1""" 

2Command-line helper functions 

3""" 

4 

5import argparse 

6import os 

7import sys 

8 

9from typing import List, Union 

10 

11 

12def less_than_zero_check(val: Union[int,float], name: str, msgs: List[str]): 

13 """ 

14 Checks whether a named numeric value is less than zero, 

15 and if so, adds to a message list. 

16 

17 Args: 

18 val: The numeric value to check. 

19 name: The name of the argument associated with the value. 

20 msgs: Message collector along with usage. 

21 """ 

22 if val < 0: 

23 msgs.append("{} must be zero or more".format(name)) 

24 

25 

26def usage(parser: argparse.ArgumentParser, msgs: List[str]=None): 

27 """ 

28 Print usage message and exit. 

29 

30 Args: 

31 parser: The command-line parser whose help we seek. 

32 msgs: Optional messages to print along with usage. 

33 """ 

34 if msgs is not None: 

35 for msg in msgs: 

36 print("{0}{1}".format(os.linesep, msg), file=sys.stderr) 

37 print(os.linesep) 

38 

39 parser.print_help() 

40 

41 sys.exit(1)