]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: client: args description/help updated
authorAleš Mrázek <ales.mrazek@nic.cz>
Tue, 3 Jan 2023 10:39:51 +0000 (11:39 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 10 Jan 2023 18:57:14 +0000 (19:57 +0100)
manager/knot_resolver_manager/cli/cmd/config.py
manager/knot_resolver_manager/cli/cmd/convert.py
manager/knot_resolver_manager/cli/cmd/metrics.py
manager/knot_resolver_manager/cli/cmd/reload.py
manager/knot_resolver_manager/cli/cmd/schema.py
manager/knot_resolver_manager/cli/cmd/stop.py
manager/knot_resolver_manager/cli/cmd/validate.py
manager/knot_resolver_manager/cli/main.py

index b790f38d1065437bf0990ef9ce6176b362c1ac33..38932d55e1048f5a1315e1a10722ffcea9a078c3 100644 (file)
@@ -57,6 +57,26 @@ def _path_comp_words(node: str, nodes: List[str], props: Dict[str, Any]) -> Comp
     elif node in props:
         node_schema = props[node]
 
+        if "anyOf" in node_schema:
+            for item in node_schema["anyOf"]:
+                print(item)
+
+        elif "type" not in node_schema:
+            pass
+
+        elif node_schema["type"] == "array":
+            if ln > 2:
+                # skip index for item in array
+                return _path_comp_words(nodes[i + 2], nodes, node_schema["items"]["properties"])
+            if "enum" in node_schema["items"]:
+                print(node_schema["items"]["enum"])
+            return {"0": "first array item", "-": "last array item"}
+        elif node_schema["type"] == "object":
+            if "additionalProperties" in node_schema:
+                print(node_schema)
+            return _path_comp_words(nodes[i + 1], nodes, node_schema["properties"])
+        return {}
+
         # arrays/lists must be handled sparately
         if node_schema["type"] == "array":
             if ln > 2:
@@ -83,19 +103,20 @@ class ConfigCommand(Command):
     def register_args_subparser(
         subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
     ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
-        config = subparser.add_parser("config", help="change configuration of a running resolver")
+        config = subparser.add_parser("config", help="Performs operations on the running resolver's configuration.")
         config.add_argument(
             "path",
             type=str,
-            help="path to the specify part of the configuration to work with",
+            help="Path (JSON pointer, RFC6901) to the configuration resources to work with.",
         )
 
-        config.add_argument("--stdin", help="read new config value on stdin", action="store_true", default=False)
+        config.add_argument("--stdin", help="Read config values from stdin.", action="store_true", default=False)
         config.add_argument(
             "value_or_file",
             type=str,
             nargs="?",
-            help="optional, new configuration values, path to the file with new values or path to the file to export data",
+            help="Optional, new configuration value, path to file with new configuraion or path to file where to save exported configuration data."
+            "If not specified, the configuration is printed.",
             default=None,
         )
 
@@ -104,7 +125,7 @@ class ConfigCommand(Command):
         operations.add_argument(
             "-s",
             "--set",
-            help="set new configuration",
+            help="Set new configuration for the resolver.",
             action="store_const",
             dest=op_dest,
             const=Operations.SET,
@@ -113,27 +134,36 @@ class ConfigCommand(Command):
         operations.add_argument(
             "-d",
             "--delete",
-            help="delete configuration",
+            help="Delete given configuration property or list item at the given index.",
             action="store_const",
             dest=op_dest,
             const=Operations.DELETE,
         )
         operations.add_argument(
-            "-g", "--get", help="get configuration", action="store_const", dest=op_dest, const=Operations.GET
+            "-g",
+            "--get",
+            help="Get current configuration from the resolver.",
+            action="store_const",
+            dest=op_dest,
+            const=Operations.GET,
         )
 
         fm_dest = "format"
         formats = config.add_mutually_exclusive_group()
         formats.add_argument(
             "--json",
-            help="JSON configuration format",
+            help="JSON format for input configuration or required format for exported configuration.",
             action="store_const",
             dest=fm_dest,
             const=Formats.JSON,
             default=Formats.JSON,
         )
         formats.add_argument(
-            "--yaml", help="YAML configuration format", action="store_const", dest=fm_dest, const=Formats.YAML
+            "--yaml",
+            help="YAML format for input configuration or required format for exported configuration.",
+            action="store_const",
+            dest=fm_dest,
+            const=Formats.YAML,
         )
 
         return config, ConfigCommand
index 729e6272c590fcb62f717298d269864e137b2caf..eda47d7c115b535ded14bf9b8e70817812c3db1f 100644 (file)
@@ -18,19 +18,19 @@ class ConvertCommand(Command):
     def register_args_subparser(
         subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
     ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
-        convert = subparser.add_parser("convert", help="convert JSON/YAML configuration to Lua script")
+        convert = subparser.add_parser("convert", help="Converts JSON or YAML configuration to Lua script.")
         convert.add_argument(
             "input_file",
             type=str,
-            help="JSON/YAML configuration input file",
+            help="File with configuration in YAML or JSON format.",
         )
 
-        convert.add_argument("--stdin", help="read new config value on stdin", action="store_true", default=False)
+        convert.add_argument("--stdin", help="Read config values from stdin.", action="store_true", default=False)
         convert.add_argument(
             "output_file",
             type=str,
             nargs="?",
-            help="optional, output Lua script file",
+            help="Optional, output file for converted configuration in Lua script. If not specified, converted configuration is printed.",
             default=None,
         )
 
index 81fc8828544d81695867d7cbc7fb5bb6bb5d5d51..44c3fb10f44b433ace0a2f9e90d8ecd500929b06 100644 (file)
@@ -17,7 +17,12 @@ class MetricsCommand(Command):
         subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
     ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
         metrics = subparser.add_parser("metrics", help="get prometheus metrics data")
-        metrics.add_argument("file", help="optional, file to export metrics to", nargs="?", default=None)
+        metrics.add_argument(
+            "file",
+            help="Optional, file where to export Prometheus metrics. If not specified, the metrics are printed.",
+            nargs="?",
+            default=None,
+        )
         return metrics, MetricsCommand
 
     @staticmethod
index 7f6d753a0329466f051c90ac721e8131050e1a65..f3b87cf9a6aca8761a7dc4092fdc03c4165eaf93 100644 (file)
@@ -14,7 +14,12 @@ class ReloadCommand(Command):
     def register_args_subparser(
         subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
     ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
-        reload = subparser.add_parser("reload", help="reload configuration file")
+        reload = subparser.add_parser(
+            "reload",
+            help="Tells the resolver to reload YAML configuration file."
+            " Old processes are replaced by new ones (with updated configuration) using rolling restarts."
+            " So there will be no DNS service unavailability during reload operation.",
+        )
 
         return reload, ReloadCommand
 
index 32c14b045a4237d22ea0591c138f04b7c3bec495..fd49e4b8efd623c219e8bd729725d3d19930aaa1 100644 (file)
@@ -16,8 +16,10 @@ class SchemaCommand(Command):
     def register_args_subparser(
         subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
     ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
-        schema = subparser.add_parser("schema", help="get JSON schema representation of the configuration")
-        schema.add_argument("file", help="optional, file to export JSON schema to", nargs="?", default=None)
+        schema = subparser.add_parser(
+            "schema", help="Reads JSON-schema repersentation of the configuration directly from the running resolver."
+        )
+        schema.add_argument("file", help="Optional, file where to export JSON-schema.", nargs="?", default=None)
         return schema, SchemaCommand
 
     @staticmethod
index c81eceb0a5e406537c42a9c97be3465678e193a5..a0519473588f782bd242cdd9769d2a50277a30c3 100644 (file)
@@ -23,5 +23,7 @@ class StopCommand(Command):
     def register_args_subparser(
         subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
     ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
-        stop = subparser.add_parser("stop", help="shutdown everything")
+        stop = subparser.add_parser(
+            "stop", help="Tells the resolver to shutdown everthing. No process will run after this command."
+        )
         return stop, StopCommand
index 9f2f0d880ce745e22f09958b318e52e630f9138f..415286b5a5ae13321a38ab202442c9c0ac62c235 100644 (file)
@@ -17,12 +17,12 @@ class ValidateCommand(Command):
     def register_args_subparser(
         subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
     ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
-        validate = subparser.add_parser("validate", help="validate JSON/YAML configuration")
+        validate = subparser.add_parser("validate", help="Validates configuration in JSON or YAML format.")
         validate.add_argument(
             "input_file",
             type=str,
             nargs="?",
-            help="JSON/YAML configuration input file",
+            help="File with configuration in YAML or JSON format.",
             default=None,
         )
 
index bed5f57cb3a17c26a07d882e0cc7506779638990..dff41df2203657345fdaf1ffd84a7a3471c8ae2a 100644 (file)
@@ -15,21 +15,25 @@ def autoimport_commands() -> None:
 
 
 def create_main_argument_parser() -> argparse.ArgumentParser:
-    parser = argparse.ArgumentParser("kresctl", description="Command-line interface for controlling Knot Resolver")
-    parser.add_argument(
-        "-i",
-        "--interactive",
-        action="store_true",
-        help="Interactive mode of kresctl utility",
-        default=False,
-        required=False,
+    parser = argparse.ArgumentParser(
+        "kresctl",
+        description="Command-line utility that helps communicate with Knot Resolver's management API."
+        "It also provides tooling to work with declarative configuration (validate, convert).",
     )
+    # parser.add_argument(
+    #     "-i",
+    #     "--interactive",
+    #     action="store_true",
+    #     help="Interactive mode of kresctl utility",
+    #     default=False,
+    #     required=False,
+    # )
     parser.add_argument(
         "-s",
         "--socket",
         action="store",
         type=str,
-        help="Path to the Unix domain socket of the configuration API",
+        help="Optional, path to Unix-domain socket or network interface of the management API.",
         default=["http+unix://%2Fvar%2Frun%2Fknot-resolver%2Fmanager.sock"],  # FIXME
         nargs=1,
         required=False,
@@ -41,10 +45,12 @@ def main() -> None:
     autoimport_commands()
     parser = create_main_argument_parser()
     install_commands_parsers(parser)
+
     namespace = parser.parse_args()
     kresctl = Kresctl(namespace, parser)
+    kresctl.execute()
 
-    if namespace.interactive or len(vars(namespace)) == 2:
-        kresctl.interactive()
-    else:
-        kresctl.execute()
+    if namespace.interactive or len(vars(namespace)) == 2:
+        kresctl.interactive()
+    else:
+        kresctl.execute()