From: Daan De Meyer Date: Wed, 10 Apr 2024 18:51:06 +0000 (+0200) Subject: Only parse arguments again if append was specified X-Git-Tag: v23~10^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28813afad3ed3d6edf898e84c4df93b1bf45297f;p=thirdparty%2Fmkosi.git Only parse arguments again if append was specified Otherwise we won't parse any arguments anyway. --- diff --git a/mkosi/config.py b/mkosi/config.py index e578a4563..326c7bba0 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1274,6 +1274,7 @@ class Args: auto_bump: bool doc_format: DocFormat json: bool + append: bool @classmethod def default(cls) -> "Args": @@ -3106,6 +3107,7 @@ def create_argument_parser(action: type[argparse.Action], chdir: bool = True) -> "--append", help="All settings passed after this argument will be parsed after all configuration files are parsed", action="store_true", + default=False, ) # These can be removed once mkosi v15 is available in LTS distros and compatibility with <= v14 # is no longer needed in build infrastructure (e.g.: OBS). @@ -3286,7 +3288,7 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu ) -> None: assert option_string is not None - if getattr(namespace, "append", False) != append: + if namespace.append != append: return if values is None and self.nargs == "?": @@ -3566,9 +3568,10 @@ def parse_config(argv: Sequence[str] = (), *, resources: Path = Path("/")) -> tu append = True - for ns in images: - ns.append = False - create_argument_parser(ConfigAction, chdir=False).parse_args(argv, ns) + if args.append: + for ns in images: + ns.append = False + create_argument_parser(ConfigAction, chdir=False).parse_args(argv, ns) for s in vars(cli_ns): if s not in SETTINGS_LOOKUP_BY_DEST: diff --git a/tests/test_json.py b/tests/test_json.py index a4c961c1a..7cb5534dc 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -40,6 +40,7 @@ def test_args(path: Optional[Path]) -> None: dump = textwrap.dedent( f"""\ {{ + "Append": true, "AutoBump": false, "Cmdline": [ "foo", @@ -61,6 +62,7 @@ def test_args(path: Optional[Path]) -> None: ) args = Args( + append = True, auto_bump = False, cmdline = ["foo", "bar"], debug = False,