]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: client: HelpCommand as default command
authorAleš Mrázek <ales.mrazek@nic.cz>
Thu, 9 Feb 2023 17:19:06 +0000 (18:19 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Thu, 9 Feb 2023 17:37:04 +0000 (17:37 +0000)
manager/knot_resolver_manager/cli/command.py

index 625ad39d52611e1960de4b6df61bf1a29f3ec3c2..4c44b32008d575828f18ac9ee8af4d6c91dd7b4a 100644 (file)
@@ -16,6 +16,13 @@ def register_command(cls: T) -> T:
     return cls
 
 
+def get_help_command() -> Type["Command"]:
+    for command in _registered_commands:
+        if command.__name__ == "HelpCommand":
+            return command
+    raise ValueError("missing HelpCommand")
+
+
 def install_commands_parsers(parser: argparse.ArgumentParser) -> None:
     subparsers = parser.add_subparsers(help="command type")
     for command in _registered_commands:
@@ -30,6 +37,8 @@ class CommandArgs:
             self.socket = f'http+unix://{quote(self.socket, safe="")}/'
         if self.socket.endswith("/"):
             self.socket = self.socket[:-1]
+        if not hasattr(namespace, "command"):
+            setattr(namespace, "command", get_help_command())
 
         self.command: Type["Command"] = namespace.command
         self.parser = parser