-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpkpass.py
executable file
·40 lines (37 loc) · 1.52 KB
/
pkpass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
"""This Module handles the CLI and any error that comes from it"""
from sys import version_info, argv
if version_info[0] < 3:
raise Exception("Python version 3 is required 3.6 and higher is actively tested")
# pylint: disable=wrong-import-position
# Reasoning for the disablement is because we want people to not try to run with python2
from argparse import ArgumentParser
from traceback import format_exception_only
from libpkpass.errors import PKPassError
from libpkpass.commands.cli import Cli
if __name__ == "__main__":
PARSER = ArgumentParser(add_help=False)
# This debug flag exists in both this parser and the main parser
# of Cli
PARSER.add_argument("--debug", action="store_true")
HIGH_LEVEL_ARGS, ARGS = PARSER.parse_known_args()
# allow '--debug' to be placed at end of command and not interrupt the subparsers
if "--debug" in argv:
argv.remove("--debug")
try:
for mesg in Cli().run():
if mesg:
print(mesg)
except PKPassError as error:
print(f"\n\n{str(type(error).__name__)}: {error.msg}")
except KeyboardInterrupt:
print("\nExiting")
# This is so that users don't see tracebacks, an error will still print out
# so that we can investigate
# Comment this out for debugging
except Exception as err: # pylint: disable=broad-except
if HIGH_LEVEL_ARGS.debug:
raise err
print(
f"Generic exception caught: \n\t{format_exception_only(type(err), err)[0]}"
)