wins, except for options taking lists in which case both lists are
combined.
-`--all`, `-a`
-
-: Iterate through all files `mkosi.*` in the `mkosi.files/`
- subdirectory, and build each as if `--config=mkosi.files/mkosi.…`
- was invoked. This is a quick way to build a large number of images
- in one go. Any additional specified command line arguments override
- the relevant options in all files processed this way.
-
-`--all-directory=`
-
-: If specified, overrides the directory the `--all` logic described
- above looks for settings files in. If unspecified, defaults to
- `mkosi.files/` in the current working directory.
-
`--incremental`, `-i`
: Enable incremental build mode. This only applies if the two-phase
type=Path,
metavar="PATH",
)
- group.add_argument(
- "-a", "--all",
- action="store_true",
- dest="all",
- default=False,
- help="Build all settings files in mkosi.files/",
- )
- group.add_argument(
- "--all-directory",
- metavar="PATH",
- type=Path,
- dest="all_directory",
- help="Specify path to directory to read settings files from",
- )
group.add_argument(
"-B",
"--auto-bump",
return args
-def parse_args(argv: Optional[Sequence[str]] = None) -> dict[str, argparse.Namespace]:
+def parse_args(argv: Optional[Sequence[str]] = None) -> argparse.Namespace:
"""Load config values from files and parse command line arguments
- Do all about config files and command line arguments parsing. If --all argument is passed
- more than one job needs to be processed. The returned tuple contains MkosiConfig
- valid for all jobs as well as a dict containing the arguments per job.
+ Do all about config files and command line arguments parsing.
"""
parser = create_parser()
else:
directory = Path.cwd()
- # Note that directory will be ignored if .all_directory or .config_path are absolute
- all_directory = directory / (args_pre_parsed.all_directory or "mkosi.files")
+ # Note that directory will be ignored if .config_path are absolute
if args_pre_parsed.config_path and not directory.joinpath(args_pre_parsed.config_path).exists():
die(f"No config file found at {directory / args_pre_parsed.config_path}")
else:
config_path = directory / "mkosi.default"
- if args_pre_parsed.all and args_pre_parsed.config_path:
- die("--all and --config= may not be combined.")
-
- # Parse everything in --all mode
- args_all = {}
- if args_pre_parsed.all:
- if not os.path.isdir(all_directory):
- die(f"all-directory {all_directory} does not exist")
- for f in os.scandir(all_directory):
- if not f.name.startswith("mkosi."):
- continue
- args = parse_args_file(argv, Path(f.path))
- args_all[f.name] = args
- # Parse everything in normal mode
- else:
- args = parse_args_file_group(argv, config_path)
-
- args = load_distribution(args)
-
- if args.distribution:
- # Parse again with any extra distribution files included.
- args = parse_args_file_group(argv, config_path, args.distribution)
-
- args_all["default"] = args
-
- return args_all
-
+ args = parse_args_file_group(argv, config_path)
+ args = load_distribution(args)
-def parse_args_file(argv: list[str], config_path: Path) -> argparse.Namespace:
- """Parse just one mkosi.* file (--all mode)."""
+ if args.distribution:
+ # Parse again with any extra distribution files included.
+ args = parse_args_file_group(argv, config_path, args.distribution)
- # Parse all parameters handled by mkosi.
- # Parameters forwarded to subprocesses such as nspawn or qemu end up in cmdline_argv.
- argv = argv[:1] + [f"@{config_path}"] + argv[1:]
-
- return create_parser().parse_args(argv)
+ return args
def parse_args_file_group(
from collections.abc import Iterator
from subprocess import CalledProcessError
-from mkosi import complete_step, parse_args, run_verb
+from mkosi import parse_args, run_verb
from mkosi.backend import MkosiException, die
def main() -> None:
args = parse_args()
- for job_name, a in args.items():
- # Change working directory if --directory is passed
- if a.directory:
- work_dir = a.directory
- if os.path.isdir(work_dir):
- os.chdir(work_dir)
- else:
- die(f"Error: {work_dir} is not a directory!")
- if len(args) > 1:
- with complete_step(f"Processing {job_name}"):
- run_verb(a)
+ if args.directory:
+ if args.directory.isdir():
+ os.chdir(args.directory)
else:
- run_verb(a)
+ die(f"Error: {args.directory} is not a directory!")
+
+ run_verb(args)
if __name__ == "__main__":