]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Only parse arguments again if append was specified
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 10 Apr 2024 18:51:06 +0000 (20:51 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 10 Apr 2024 19:31:09 +0000 (21:31 +0200)
Otherwise we won't parse any arguments anyway.

mkosi/config.py
tests/test_json.py

index e578a4563d8d34b3b3bb4bdf1dd01d092ecbfae7..326c7bba075eddcf9d3c49e9e5cbbd9de337753a 100644 (file)
@@ -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:
index a4c961c1afd3009a8197534c1c73b96fdff3c117..7cb5534dc512cadae1ba34ed1742fa9406a364ff 100644 (file)
@@ -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,