]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
initrd: split out argument parser creation to helper function
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 16 Feb 2025 20:39:19 +0000 (21:39 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Mar 2025 12:36:34 +0000 (13:36 +0100)
mkosi/initrd.py

index c7731ef94473e42dab458c0bec73b4f5f033d3b6..7be2216ea4bd0163c9d903e52c3b55fdf80c026d 100644 (file)
@@ -98,6 +98,52 @@ class KernelInstallContext:
         )
 
 
+def create_parser() -> argparse.ArgumentParser:
+    parser = argparse.ArgumentParser(
+        prog="mkosi-initrd",
+        description="Build initrds or unified kernel images for the current system using mkosi",
+        allow_abbrev=False,
+        usage="mkosi-initrd [options...]",
+    )
+    parser.add_argument(
+        "-o",
+        "--output",
+        metavar="NAME",
+        help="Output name",
+        default="initrd",
+    )
+    parser.add_argument(
+        "--kernel-image",
+        metavar="KERNEL_IMAGE",
+        help="Kernel image",
+        type=Path,
+    )
+    parser.add_argument(
+        "-t",
+        "--format",
+        choices=[str(OutputFormat.cpio), str(OutputFormat.uki), str(OutputFormat.directory)],
+        help="Output format (CPIO archive, UKI or local directory)",
+        default="cpio",
+    )
+    parser.add_argument(
+        "-g",
+        "--generic",
+        help="Build a generic initrd without host-specific kernel modules",
+        action="store_true",
+        default=False,
+    )
+    parser.add_argument(
+        "--profile",
+        choices=InitrdProfile.values(),
+        help="Which profiles to enable for the initrd",
+        action="append",
+        default=[],
+    )
+
+    initrd_common_args(parser)
+    return parser
+
+
 def process_crypttab(staging_dir: str) -> list[str]:
     cmdline = []
 
@@ -210,50 +256,7 @@ def include_system_config(name: str) -> list[str]:
 def main() -> None:
     log_setup()
 
-    parser = argparse.ArgumentParser(
-        prog="mkosi-initrd",
-        description="Build initrds or unified kernel images for the current system using mkosi",
-        allow_abbrev=False,
-        usage="mkosi-initrd [options...]",
-    )
-    parser.add_argument(
-        "-o",
-        "--output",
-        metavar="NAME",
-        help="Output name",
-        default="initrd",
-    )
-    parser.add_argument(
-        "--kernel-image",
-        metavar="KERNEL_IMAGE",
-        help="Kernel image",
-        type=Path,
-    )
-    parser.add_argument(
-        "-t",
-        "--format",
-        choices=[str(OutputFormat.cpio), str(OutputFormat.uki), str(OutputFormat.directory)],
-        help="Output format (CPIO archive, UKI or local directory)",
-        default="cpio",
-    )
-    parser.add_argument(
-        "-g",
-        "--generic",
-        help="Build a generic initrd without host-specific kernel modules",
-        action="store_true",
-        default=False,
-    )
-    parser.add_argument(
-        "--profile",
-        choices=InitrdProfile.values(),
-        help="Which profiles to enable for the initrd",
-        action="append",
-        default=[],
-    )
-
-    initrd_common_args(parser)
-
-    args = parser.parse_args()
+    args = create_parser().parse_args()
 
     if args.show_documentation:
         with resource_path(mkosi.resources) as r: