namespace = argparse.Namespace()
argparser = create_argument_parser(MkosiAction)
argparser.parse_args(argv, namespace)
+ cli_ns = copy.deepcopy(namespace)
args = load_args(namespace)
finalize_defaults(namespace, defaults)
images = [namespace]
+ for s in vars(cli_ns):
+ if s not in SETTINGS_LOOKUP_BY_DEST:
+ continue
+
+ if getattr(cli_ns, s) is None:
+ continue
+
+ if isinstance(getattr(cli_ns, s), (list, tuple)):
+ continue
+
+ if any(getattr(config, s) == getattr(cli_ns, s) for config in images):
+ continue
+
+ setting = SETTINGS_LOOKUP_BY_DEST[s]
+
+ die(f"{setting.long}={getattr(cli_ns, s)} was specified on the command line but is not allowed to be configured by any images.",
+ hint="Prefix the setting with '@' in the image configuration file to allow overriding it from the command line.")
+
if not images:
die("No images defined in mkosi.images/")
assert config.image_id == "base"
with chdir(d):
- _, [config] = parse_config(["--distribution", "fedora", "--architecture", "x86-64"])
+ _, [config] = parse_config(["--distribution", "fedora"])
# mkosi.conf sets a default distribution, so the CLI should take priority.
assert config.distribution == Distribution.fedora
- # mkosi.conf sets overrides the architecture, so whatever is specified on the CLI should be ignored.
- assert config.architecture == Architecture.arm64
+
+ # Any architecture set on the CLI is overridden by the config file, and we should complain loudly about that.
+ with chdir(d), pytest.raises(SystemExit):
+ _, [config] = parse_config(["--architecture", "x86-64"])
(d / "mkosi.conf.d").mkdir()
(d / "mkosi.conf.d/d1.conf").write_text(