-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (23 loc) · 934 Bytes
/
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
import sys
from argparse import ArgumentParser
from todd import pkg_index_exists, subcommands
def main() -> bool:
parser = ArgumentParser(description="ToddLinux Builder.")
parser.add_argument("subcommand", help="subcommand to do", type=str)
parser.add_argument("subcommand_args", help="subcommand args", nargs="*")
args = parser.parse_args()
subcommand_name = args.subcommand
subcommand_args = args.subcommand_args
if not pkg_index_exists("/"):
print("Package index doesn't exist.")
return False
if not subcommand_name in subcommands.SUBCOMMANDS:
print("No such subcommand:", subcommand_name)
return False
subcommand = subcommands.SUBCOMMANDS[subcommand_name]
if not subcommand.validate_args(subcommand_args):
return False
subcommand.handle(args.subcommand_args)
return True
if __name__ == "__main__":
sys.exit(0 if main() else 1)