diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-03-14 16:34:42 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2022-03-14 16:34:42 +0100 |
commit | 64147338d7f4f7ead19a618627b8b4ae4e7542ce (patch) | |
tree | afbf30ba4fbb4a52191299dc41c188100df52925 | |
parent | bf9b0b538b163ef1f05391511d0c01516ad9f2a0 (diff) |
Remove the need for a _main method
-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. |