-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
45 lines (36 loc) · 1.29 KB
/
cli.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
41
42
43
44
45
import sys
import logging
from core.interfaces.command_interface import ICommand
from core.manager.command_factory import CommandFactory
from core.settings.config import Config
from core.settings.database import Database
from core.utils.exceptions import PathNotFound, CommandNotFound
from core.utils.logging import setup_logging
setup_logging()
def main() -> None:
try:
cf = Config()
database = Database()
database.setup()
# Parse arguments using argparse
if len(sys.argv) < 2:
raise CommandNotFound("Usage 'cli.py <command>'")
command_name: str = sys.argv[1]
param: str = sys.argv[2] if len(sys.argv) > 2 else "Unknown"
# # Get command and execute
command: ICommand = CommandFactory.get_command(cf, command_name, param)
command.execute()
except ValueError as e:
logging.error(f"[Value]: {e}")
except PathNotFound as e:
logging.error(f"[Path]: {e}")
except FileNotFoundError as e:
logging.error(f"[File]: {e}")
except CommandNotFound as e:
logging.error(f"[Command]: {e}")
except Exception as e:
logging.error(f"[Unexpected]: {e}")
finally:
database.close()
if __name__ == "__main__":
main()