Coverage for paikalta/cli.py: 92.86%
22 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 21:11:26 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 21:11:26 +00:00
1"""From the place (Finnish: paikalta) we derive the name - command line interface."""
3import argparse
4import sys
5from typing import no_type_check
7import paikalta.api as api
8from paikalta import (
9 FAIL,
10 SUCC,
11)
14@no_type_check
15def parser():
16 """Implementation of command line API returning parser."""
17 impl = argparse.ArgumentParser(description='Verifies or modifies the name of a CSAF 2.0 advisory file')
18 impl.add_argument('input_file', type=str, help='CSAF advisory file to verify or modify the filename of')
19 impl.add_argument('-p', '--print', dest='echo', action='store_true', help='Prints the correct filename')
20 impl.add_argument(
21 '-l',
22 '--labels',
23 dest='labels',
24 type=str,
25 help='Comma separate pair of SUCC,FAIL labels (in that order) activating verbose mode',
26 )
27 impl.add_argument(
28 '-v',
29 '--verbose',
30 dest='verbose',
31 action='store_true',
32 help=f'Prints the logic result as either {SUCC} or {FAIL} if not overridden by --label option',
33 )
34 impl.add_argument(
35 '-a',
36 '--add',
37 dest='add',
38 action='store_true',
39 help=(
40 'Writes the CSAF advisory file to the correct filename if different'
41 ' - will overrule -u/--update if given in addition'
42 ),
43 )
44 impl.add_argument(
45 '-u',
46 '--update',
47 dest='update',
48 action='store_true',
49 help=(
50 'Renames the CSAF advisory file to the correct filename if necessary'
51 ' - will be overruled by -a/--add if given in addition'
52 ),
53 )
54 return impl
57@no_type_check
58def app(argv=None):
59 """Drive the verification or modification of advisory file(name)s per CSAF 2.0 rules."""
60 argv = sys.argv[1:] if argv is None else argv
61 options = parser().parse_args(argv)
62 return api.process(options)
65if __name__ == '__main__': 65 ↛ 66line 65 didn't jump to line 66, because the condition on line 65 was never true
66 sys.exit(app(sys.argv[1:]))