From: Zbigniew Jędrzejewski-Szmek Date: Sun, 16 Feb 2025 20:39:19 +0000 (+0100) Subject: initrd: split out argument parser creation to helper function X-Git-Tag: v26~322^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67c0faa1ca9ad9d4794a7b0fa33a511dbe893b8d;p=thirdparty%2Fmkosi.git initrd: split out argument parser creation to helper function --- diff --git a/mkosi/initrd.py b/mkosi/initrd.py index c7731ef94..7be2216ea 100644 --- a/mkosi/initrd.py +++ b/mkosi/initrd.py @@ -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: