diff options
-rw-r--r-- | hazwaz/command.py | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/hazwaz/command.py b/hazwaz/command.py index 28c3fa5..e966792 100644 --- a/hazwaz/command.py +++ b/hazwaz/command.py @@ -47,7 +47,7 @@ class MainCommand: epilog=epilog, ) self.add_arguments(self.parser) - self.parser.set_defaults(func=self.main) + self.parser.set_defaults(subcommand=self) self.subparsers = self.parser.add_subparsers() for sub in self.commands: sub_help = _get_first_docstring_line(sub) @@ -58,9 +58,9 @@ class MainCommand: epilog=sub_epilog, ) sub.add_arguments(sub_parser) - sub_parser.set_defaults(func=sub._main) + sub_parser.set_defaults(subcommand=sub) - def main(self, args): + def main(self): """ The main function for a command with no subcommands. @@ -104,7 +104,8 @@ class MainCommand: else: logger.setLevel(logging.WARNING) - self.args.func(self.args) + self.args.subcommand.args = self.args + self.args.subcommand.main() class Command: @@ -127,10 +128,6 @@ class Command: if self.name is None: self.name = self.__class__.__name__.lower() - def _main(self, args): - self.args = args - self.main() - def add_arguments(self, parser: argparse.ArgumentParser): """ Add argparse arguments to an existing parser. |