diff --git a/.gitignore b/.gitignore index 58d60cd..b7298bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ old/ -VoidServiceControl/main.py __pycache__ .idea .venv diff --git a/VoidServiceControl/classes.py b/VoidServiceControl/classes.py index 0186c76..79ddd71 100644 --- a/VoidServiceControl/classes.py +++ b/VoidServiceControl/classes.py @@ -70,12 +70,10 @@ class Args(object): """ Checks the arguments """ - if len(self.__arguments) == 0: - raise TypeError(lang.errors["usage"]) - if len(self.__arguments) != 2 and self.__arguments[0] not in Arg.HELP.value: - raise TypeError(lang.errors["usage"]) - if self.__arguments[0] in Arg.HELP.value: + if len(self.__arguments) == 1 and self.__arguments[0] in Arg.HELP.value: raise Help() + if len(self.__arguments) < 2: + raise TypeError(lang.errors["usage"]) if self.__arguments[0] not in Arg.all(): raise TypeError(lang.errors["args"]) @@ -91,7 +89,7 @@ class Args(object): def __iter__(self): yield self.__action() - yield self.__arguments[1] + yield self.__arguments[1:] class Service(object): diff --git a/VoidServiceControl/main.py b/VoidServiceControl/main.py new file mode 100755 index 0000000..36e0c9f --- /dev/null +++ b/VoidServiceControl/main.py @@ -0,0 +1,21 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +from VoidServiceControl.classes import Su, Interface, Args, Help + + +def main() -> None: + try: + Su() + action, services = tuple(Args()) + for service_name in services: + service = Interface(service_name) + service.action(action) + del service + except TypeError as e: + print(f"{e}\n\n{Help()}") + except (ValueError, PermissionError, Help) as e: + print(e) + + +if __name__ == '__main__': + main()