-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (41 loc) · 1.4 KB
/
main.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
46
47
48
49
50
51
52
53
54
"""Main module"""
import argparse
import sys
import importlib
import config
commands = {
"init": "InitCommand",
"add": "AddCommand",
"checkout": "CheckoutCommand",
"commit": "CommitCommand",
"diff": "DiffCommand",
"version": "VersionCommand",
"reset": "ResetCommand",
# "stash": "StashCommand",
# "mv": "MvCommand",
"publish": "PublishCommand",
}
class VersionControl:
"""Version Controll"""
def __init__(self) -> None:
self.parser = argparse.ArgumentParser(description="A version control system")
self.subparsers = self.parser.add_subparsers(dest="command")
self.commands = {}
for module_name, attr in commands.items():
module = importlib.import_module(f"commands.{module_name}")
command_module = getattr(module, attr)
self.commands[module_name] = command_module(self.subparsers)
def run(self):
"""Main run method entry point"""
if len(sys.argv) == 1:
self.parser.print_help()
return
args = self.parser.parse_args()
if not config.path_meta.is_file() and not args.command in ("init", "publish"):
print("Version Control not initialized.")
return
command_module = self.commands[args.command]
command_module.run(args)
if __name__ == "__main__":
version_control = VersionControl()
version_control.run()