From 64147338d7f4f7ead19a618627b8b4ae4e7542ce Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Mon, 14 Mar 2022 16:34:42 +0100 Subject: Remove the need for a _main method --- hazwaz/command.py | 13 +++++-------- 1 file 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. -- cgit v1.2.3