]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make Environment= match without value check if given key is in env
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 16 May 2024 14:53:36 +0000 (16:53 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 16 May 2024 16:43:12 +0000 (18:43 +0200)
mkosi/config.py
mkosi/resources/mkosi.md
tests/test_config.py

index f58b2ca8f5c0cb7830a131a82d8073b441e0e940..78321248f1af76e0082e309c448ab9b6087326b5 100644 (file)
@@ -587,7 +587,7 @@ def config_make_string_matcher(allow_globs: bool = False) -> ConfigMatchCallback
 def config_match_key_value(match: str, value: dict[str, str]) -> bool:
     k, sep, v = match.partition("=")
     if not sep:
-        die(f"{match} is not a key=value pair")
+        return k in value
 
     return value.get(k, None) == v
 
index b76f8622d44cf0a13d6d7fc2cf1b374201579516..a67cbacc6ddfae9a5cdf874d4b290d654928ab28 100644 (file)
@@ -1858,7 +1858,8 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 `Environment=`
 
 : Matches against a specific key/value pair configured with
-  `Environment=`.
+  `Environment=`. If no value is provided, check if the given key is in
+  the environment regardless of which value it has.
 
 | Matcher                  | Globs | Rich Comparisons | Default                               |
 |--------------------------|-------|------------------|---------------------------------------|
index 8d58888717c926ee05db3a00c3d58a09db55c24d..e7cea38795e8b65d5d97a7d39c012feb7ee47bff 100644 (file)
@@ -835,6 +835,24 @@ def test_match_environment(tmp_path: Path) -> None:
         _, [conf] = parse_config(["--environment", "MYEN=abd"])
         assert conf.image_id != "matched"
 
+    (d / "mkosi.conf").write_text(
+        """\
+        [Match]
+        Environment=MYENV
+
+        [Content]
+        ImageId=matched
+        """
+    )
+
+    with chdir(d):
+        _, [conf] = parse_config(["--environment", "MYENV=abc"])
+        assert conf.image_id == "matched"
+        _, [conf] = parse_config(["--environment", "MYENV=abd"])
+        assert conf.image_id == "matched"
+        _, [conf] = parse_config(["--environment", "MYEN=abc"])
+        assert conf.image_id != "matched"
+
 
 @pytest.mark.parametrize(
     "skel,pkgmngr", itertools.product(