Coverage for /builds/svesch/cikit/src/cikit/ci/main.py: 88%
23 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-09 14:17 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-09 14:17 +0000
1# SPDX-License-Identifier: GPL-3.0-or-later
2"""Main command line entry point for cikit CI commands.
4Author:
5 Sven Schlender
6Date:
7 2026-06-16
8"""
10import argparse
11import sys
13from cikit.ci.loader import register_commands
14from cikit.errors import CiToolsError
17def build_parser() -> argparse.ArgumentParser:
18 """Build the complete command line parser.
20 Returns:
21 Configured parser with all detected CI commands.
22 """
23 parser = argparse.ArgumentParser(prog="cikit",
24 description="Run local and CI helper commands.")
26 parser.add_argument("-v", "--verbose", action="store_true",
27 help="Enable verbose logging output.")
28 parser.add_argument("-n", "--name",
29 help="Override the logical run name used for cikit data.")
31 subparsers = parser.add_subparsers(dest="command", required=True)
32 register_commands(subparsers)
34 return parser
37def main_unsafe() -> int:
38 """Parse arguments and dispatch the selected command.
40 Returns:
41 Exit code from the selected command.
42 """
43 parser = build_parser()
44 args = parser.parse_args()
46 return args.func(args)
49def main():
50 """Run command line entry point.
52 Raises:
53 SystemExit: Always exits with the command exit code.
54 """
55 try:
56 sys.exit(main_unsafe())
57 except CiToolsError as exp:
58 print(f"Error: {exp}", file=sys.stderr)
59 sys.exit(exp.exit_code)
61if __name__ == "__main__": 61 ↛ exitline 61 didn't exit the module because the condition on line 61 was always true
62 main()