]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
python/knot_resolver: parse arguments
authorAleš Mrázek <ales.mrazek@nic.cz>
Tue, 30 Jun 2026 08:25:31 +0000 (10:25 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 30 Jun 2026 23:11:37 +0000 (01:11 +0200)
python/knot_resolver/args.py [new file with mode: 0644]

diff --git a/python/knot_resolver/args.py b/python/knot_resolver/args.py
new file mode 100644 (file)
index 0000000..23c9b82
--- /dev/null
@@ -0,0 +1,50 @@
+from __future__ import annotations
+
+import argparse
+from dataclasses import dataclass
+
+from .constants import CONFIG_FILE, VERSION
+
+
+@dataclass
+class KresArgs:
+    loglevel: str
+    logtarget: str
+    config: list[str]
+
+
+def parse_args() -> KresArgs:
+    parser = argparse.ArgumentParser(
+        description="A modern, high-performance, modular DNS resolver with DNSSEC validation and advanced policy.",
+    )
+    parser.add_argument(
+        "-V",
+        "--version",
+        help="Get version",
+        action="version",
+        version=VERSION,
+    )
+    parser.add_argument(
+        "--loglevel",
+        default="notice",
+        choices=["debug", "info", "notice", "warning", "error", "critical"],
+        help="Startup logging level before the configuration is loaded.",
+    )
+    parser.add_argument(
+        "--logtarget",
+        default="stderr",
+        choices=["stdout", "stderr", "syslog"],
+        help="Startup logging target before the configuration is loaded.",
+    )
+    parser.add_argument(
+        "-c",
+        "--config",
+        help="Optional, path to one or more configuration files (YAML/JSON).",
+        type=str,
+        nargs="+",
+        required=False,
+        default=[str(CONFIG_FILE)],
+    )
+
+    args_ns = parser.parse_args()
+    return KresArgs(**vars(args_ns))