sp-hydra-veil-cli/cli/__main__.py
2026-05-30 08:25:00 -05:00

48 lines
No EOL
1.6 KiB
Python

from core.Constants import Constants
from core.Errors import UnknownConnectionTypeError
from cli.helpers import get_distribution
from cli.commands import all_commands
from cli.commands import get_set, sync_update
from pathlib import Path
import argparse
import sys
def _handle_exception(identifier, message, traceback):
if issubclass(identifier, UnknownConnectionTypeError):
print('Please specify the desired connection method and try again.\n')
else:
sys.__excepthook__(identifier, message, traceback)
if __name__ == '__main__':
Path(Constants.HV_CONFIG_HOME).mkdir(parents=True, exist_ok=True)
Path(Constants.HV_DATA_HOME).mkdir(parents=True, exist_ok=True)
sys.excepthook = _handle_exception
distribution = get_distribution()
parser = argparse.ArgumentParser(prog=distribution.name)
parser.add_argument('--version', '-v', action='version', version=f'{distribution.name} v{distribution.version}')
subparsers = parser.add_subparsers(title='commands', dest='command')
for command in all_commands:
command.register(subparsers)
arguments = parser.parse_args()
if arguments.command is None:
parser.print_help()
elif arguments.command in (get_set.NAME, get_set.NAME_SET):
get_set.handle(arguments, parser)
elif arguments.command in (sync_update.NAME_SYNC, sync_update.NAME_UPDATE):
sync_update.handle(arguments, parser)
else:
command = next((c for c in all_commands if getattr(c, 'NAME', None) == arguments.command), None)
if command:
command.handle(arguments, parser)