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
`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 |
|--------------------------|-------|------------------|---------------------------------------|
_, [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(