#compdef mkosi
# SPDX-License-Identifier: LGPL-2.1-or-later
# shellcheck shell=zsh

_mkosi_verb(){
    if (( CURRENT == 1 )); then
        _describe -t commands 'mkosi verb' _mkosi_verbs
    else
        local curcontext="$curcontext"
        if [[ "$curcontext" == ':complete:mkosi:argument-rest' ]]; then
            _files
        fi
    fi
}

declare -a _mkosi_verbs=(build clean summary cat-config shell boot vm qemu ssh serve bump help genkey documentation journalctl coredumpctl burn dependencies completion sysupdate box sandbox init latest-snapshot)

_arguments -s \
    '(- *)'{-h,--help}'[Show this help]' \
    '(- *)--version[Show package version]' \
    '(-f --force)'{-f,--force}'[Remove existing image file before operation]' \
    '(-C --directory)'{-C,--directory}'[Change to specified directory before doing anything]:directory:_files -f' \
    '--debug[Turn on debugging output]' \
    '--debug-shell[Spawn an interactive shell in the image if a chroot command fails]' \
    '--debug-workspace[When an error occurs, the workspace directory will not be deleted]' \
    '--debug-sandbox[Run mkosi-sandbox with strace]' \
    '--no-pager[Enable paging for long output]' \
    '--genkey-valid-days[Number of days keys should be valid when generating keys]' \
    '--genkey-common-name[Template for the CN when generating keys]' \
    '(-B --auto-bump)'{-B,--auto-bump}'[Automatically bump image version after building]' \
    '--doc-format[The format to show documentation in]:arg:(auto markdown man pandoc system)' \
    '--json[Show summary as JSON]' \
    '(-w --wipe-build-dir)'{-w,--wipe-build-dir}'[Remove the build directory before building the image]' \
    '(-R --rerun-build-scripts)'{-R,--rerun-build-scripts}'[Run build scripts even if the image is not rebuilt]' \
    '(-I --include)'{-I,--include}'[Include configuration from the specified file or directory]' \
    '--profile[Build the specified profiles]' \
    '--dependency[Specify other images that this image depends on]' \
    '--minimum-version[Specify the minimum required mkosi version]' \
    '--configure-script[Configure script to run before doing anything]' \
    '--pass-environment[Environment variables to pass to subimages]' \
    '(-d --distribution)'{-d,--distribution}'[Distribution to install]:arg:(fedora debian kali ubuntu postmarketos arch opensuse mageia centos rhel rhel-ubi openmandriva rocky alma azure custom )' \
    '(-r --release)'{-r,--release}'[Distribution release to install]' \
    '--architecture[Override the architecture of installation]:arg:(alpha arc arm arm64 ia64 loongarch64 mips-le mips64-le parisc ppc ppc64 ppc64-le riscv32 riscv64 s390 s390x tilegx x86 x86-64 )' \
    '(-m --mirror)'{-m,--mirror}'[Distribution mirror to use]' \
    '--snapshot[Distribution snapshot to use]' \
    '--local-mirror[Use a single local, flat and plain mirror to build the image]' \
    '--repository-key-check[Controls signature and key checks on repositories]' \
    '--repository-key-fetch[Controls whether distribution GPG keys can be fetched remotely]' \
    '--repositories[Repositories to use]' \
    '(-t --format)'{-t,--format}'[Output Format]:arg:(confext cpio directory disk esp none portable sysext tar uki oci addon )' \
    '--manifest-format[Manifest Format]' \
    '(-o --output)'{-o,--output}'[Output name]' \
    '--output-extension[Output extension]' \
    '--compress-output[Enable whole-output compression (with images or archives)]' \
    '--compress-level[Set the compression level to use]' \
    '(-O --output-directory)'{-O,--output-directory}'[Output directory]' \
    '--output-mode[Set file system access mode for image]' \
    '--image-version[Set version for image]' \
    '--image-id[Set ID for image]' \
    '--split-artifacts[Split artifacts out of the final image]' \
    '--repart-directory[Directory containing systemd-repart partition definitions]' \
    '--sector-size[Set the disk image sector size]' \
    '--overlay[Only output the additions on top of the given base trees]' \
    '--seed[Set the seed for systemd-repart]' \
    '--clean-script[Clean script to run after cleanup]' \
    '(-p --package)'{-p,--package}'[Add an additional package to the OS image]' \
    '--build-package[Additional packages needed for build scripts]' \
    '--volatile-package[Packages to install after executing build scripts]' \
    '--package-directory[Specify a directory containing extra packages]' \
    '--volatile-package-directory[Specify a directory containing extra volatile packages]' \
    '--with-recommends[Install recommended packages]' \
    '--with-docs[Install documentation]' \
    '--base-tree[Use the given tree as base tree (e.g. lower sysext layer)]' \
    '--skeleton-tree[Use a skeleton tree to bootstrap the image before installing anything]' \
    '--extra-tree[Copy an extra tree on top of image]' \
    '--remove-package[Remove package from the image OS image after installation]' \
    '--remove-files[Remove files from built image]' \
    '--clean-package-metadata[Remove package manager database and other files]' \
    '--source-date-epoch[Set the $SOURCE_DATE_EPOCH timestamp]' \
    '--sync-script[Sync script to run before starting the build]' \
    '--prepare-script[Prepare script to run inside the image before it is cached]' \
    '--build-script[Build script to run inside image]' \
    '--postinst-script[Postinstall script to run inside image]' \
    '--finalize-script[Postinstall script to run outside image]' \
    '--postoutput-script[Output postprocessing script to run outside image]' \
    '--bootable[Generate ESP partition with systemd-boot and UKIs for installed kernels]' \
    '--bootloader[Specify which UEFI bootloader to use]:arg:(none uki systemd-boot grub uki-signed systemd-boot-signed grub-signed )' \
    '--bios-bootloader[Specify which BIOS bootloader to use]:arg:(none grub )' \
    '--shim-bootloader[Specify whether to use shim]:arg:(none signed unsigned )' \
    '--unified-kernel-images[Specify whether to use UKIs with grub/systemd-boot in UEFI mode]' \
    '--unified-kernel-image-format[Specify the format used for the UKI filename]' \
    '--uki-profile[Configuration files to generate UKI profiles]' \
    '--initrd[Add a user-provided initrd to image]' \
    $'--microcode-host[Only include the host CPU\'s microcode]' \
    '--initrd-profile[Which profiles to enable for the default initrd]:arg:(lvm network nfs pkcs11 plymouth raid)' \
    '--initrd-package[Add additional packages to the default initrd]' \
    '--initrd-volatile-package[Packages to install in the initrd that are not cached]' \
    '--devicetrees[Devicetree(s) to be used by the booting kernel]' \
    '--splash[Splash screen image to be used by the booting kernel]' \
    '--kernel-command-line[Set the kernel command line (only bootable images)]' \
    '--kernel-modules-include[Include the specified kernel modules in the image]' \
    '--kernel-modules-exclude[Exclude the specified kernel modules from the image]' \
    '--kernel-modules[Include/exclude the specified kernel modules in the image]' \
    '--kernel-modules-include-host[Include the currently loaded modules on the host in the image]' \
    '--kernel-modules-initrd[When building a bootable image, add an extra initrd containing the kernel modules]' \
    '--kernel-modules-initrd-include[When building a kernel modules initrd, include the specified kernel modules]' \
    '--kernel-modules-initrd-exclude[When building a kernel modules initrd, exclude the specified kernel modules]' \
    '--kernel-initrd-modules[Include/exclude modules in the initrd]' \
    '--kernel-modules-initrd-include-host[When building a kernel modules initrd, include the currently loaded modules on the host in the image]' \
    '--firmware-include[Include the specified firmware in the image]' \
    '--firmware-exclude[Exclude the specified firmware from the image]' \
    '--firmware-files[Include/exclude the specified firmware in the image]' \
    '--locale[Set the system locale]' \
    '--locale-messages[Set the messages locale]' \
    '--keymap[Set the system keymap]' \
    '--timezone[Set the system timezone]' \
    '--hostname[Set the system hostname]' \
    '--root-password[Set the password for root]' \
    '--root-shell[Set the shell for root]' \
    '--machine-id[Set the machine ID to use]' \
    '(-a --autologin)'{-a,--autologin}'[Enable root autologin]' \
    '--make-initrd[Make sure the image can be used as an initramfs]' \
    $'--ssh[Set up SSH access from the host to the final image via \'mkosi ssh\']:arg:(always auto runtime never )' \
    '--selinux-relabel[Specify whether to relabel all files with setfiles]' \
    '--secure-boot[Sign the resulting kernel/initrd image for UEFI SecureBoot]' \
    '--secure-boot-auto-enroll[Automatically enroll the secureboot signing key on first boot]' \
    '--secure-boot-key[UEFI SecureBoot private key]' \
    '--secure-boot-key-source[The source to use to retrieve the secure boot signing key]' \
    '--secure-boot-certificate[UEFI SecureBoot certificate in X509 format]' \
    '--secure-boot-certificate-source[The source to use to retrieve the secure boot signing certificate]' \
    '--secure-boot-sign-tool[Tool to use for signing PE binaries for secure boot]:arg:(auto sbsign systemd-sbsign )' \
    '--verity[Configure whether to enforce or disable verity partitions for disk images]:arg:(disabled hash signed defer auto)' \
    '--verity-key[Private key for signing verity signature]' \
    '--verity-key-source[The source to use to retrieve the verity signing key]' \
    '--verity-certificate[Certificate for signing verity signature in X509 format]' \
    '--verity-certificate-source[The source to use to retrieve the verity signing certificate]' \
    '--sign-expected-pcr[Measure the components of the unified kernel image (UKI) and embed the PCR signature into the UKI]' \
    '--sign-expected-pcr-key[Private key for signing expected PCR signature]' \
    '--sign-expected-pcr-key-source[The source to use to retrieve the expected PCR signing key]' \
    '--sign-expected-pcr-certificate[Certificate for signing expected PCR signature in X509 format]' \
    '--sign-expected-pcr-certificate-source[The source to use to retrieve the expected PCR signing certificate]' \
    '--passphrase[Path to a file containing the passphrase to use when LUKS encryption is selected]' \
    '--checksum[Write SHA256SUMS file]' \
    '--sign[Write and sign SHA256SUMS file]' \
    '--key[GPG key to use for signing]' \
    '--openpgp-tool[OpenPGP implementation to use for signing]' \
    '--tools-tree[Look up programs to execute inside the given tree]' \
    '--tools-tree-distribution[Set the distribution to use for the default tools tree]:arg:(fedora debian kali ubuntu postmarketos arch opensuse mageia centos rhel rhel-ubi openmandriva rocky alma azure custom )' \
    '--tools-tree-release[Set the release to use for the default tools tree]' \
    '--tools-tree-profile[Which profiles to enable for the default tools tree]:arg:(devel misc package-manager runtime)' \
    '--tools-tree-mirror[Set the mirror to use for the default tools tree]' \
    '--tools-tree-repository[Repositories to use for the default tools tree]' \
    '--tools-tree-sandbox-tree[Sandbox trees for the default tools tree]' \
    '--tools-tree-package[Add additional packages to the default tools tree]' \
    '--tools-tree-package-directory[Specify a directory containing extra tools tree packages]' \
    '--tools-tree-certificates[Use certificates from the tools tree]' \
    '--extra-search-path[List of comma-separated paths to look for programs before looking in PATH]' \
    '(-i --incremental)'{-i,--incremental}'[Make use of and generate intermediary cache images]:arg:(yes no strict)' \
    '--cache-only[Only use the package cache when installing packages]:arg:(always auto none metadata never )' \
    '--sandbox-tree[Use a sandbox tree to configure the various tools that mkosi executes]' \
    '--workspace-directory[Workspace directory]' \
    '--cache-directory[Incremental cache directory]' \
    '--cache-key[Cache key to use within cache directory]' \
    '--package-cache-directory[Package cache directory]' \
    '--build-directory[Path to use as persistent build directory]' \
    '--build-key[Build key to use within build directory]' \
    '--use-subvolumes[Use btrfs subvolumes for faster directory operations where possible]' \
    '--repart-offline[Build disk images without using loopback devices]' \
    '--history[Whether mkosi can store information about previous builds]' \
    '--build-sources[Path for sources to build]' \
    '--build-sources-ephemeral[Make build sources ephemeral when running scripts]:arg:(yes no buildcache)' \
    '(-E --environment)'{-E,--environment}'[Set an environment variable when running scripts]' \
    '--env-file[Environment files to set when running scripts]' \
    '(-T --with-tests)'{-T,--with-tests}'[Do not run tests as part of build scripts, if supported]' \
    '--with-network[Run build and postinst scripts with network access (instead of private network)]' \
    '--proxy-url[Set the proxy to use]' \
    $'--proxy-exclude[Don\'t use the configured proxy for the specified host(s)]' \
    '--proxy-peer-certificate[Set the proxy peer certificate]' \
    '--proxy-client-certificate[Set the proxy client certificate]' \
    '--proxy-client-key[Set the proxy client key]' \
    '--settings[Add in .nspawn settings file]' \
    '--ephemeral[If specified, the container/VM is run with a temporary snapshot of the output image that is removed immediately when the container/VM terminates]' \
    '--credential[Pass a systemd credential to a systemd-nspawn container or a virtual machine]' \
    '--kernel-command-line-extra[Append extra entries to the kernel command line when booting the image]' \
    '--runtime-tree[Additional mounts to add when booting the image]' \
    '--runtime-size[Grow disk images to the specified size before booting them]' \
    '--runtime-network[Set networking backend to use when booting the image]:arg:(interface user none )' \
    '--runtime-build-sources[Mount build sources and build directory in /work when booting the image]' \
    '--bind-user[Bind current user from host into container or virtual machine]' \
    '--unit-property[Set properties on the scopes spawned by systemd-nspawn or systemd-run]' \
    '--ssh-key[Private key for use with mkosi ssh in PEM format]' \
    '--ssh-certificate[Certificate for use with mkosi ssh in X509 format]' \
    '--vmm[Set the virtual machine monitor to use for mkosi vm]:arg:(qemu vmspawn )' \
    '--machine[Set the machine name to use when booting the image]' \
    '--forward-journal[Set the path used to store forwarded machine journals]' \
    '--sysupdate-directory[Directory containing systemd-sysupdate transfer definitions]' \
    '--console[Configure the virtual machine console mode to use]' \
    '--cpus[Configure number of CPUs in virtual machine]' \
    $'--ram[Configure guest\'s RAM size]' \
    $'--maxmem[Configure guest\'s MaxMem size]' \
    '--kvm[Configure whether to use KVM or not]' \
    '--cxl[Enable CXL device support]' \
    '--vsock[Configure whether to use vsock or not]' \
    '--vsock-cid[Specify the vsock connection ID to use]' \
    '--tpm[Configure whether to use a virtual tpm or not]' \
    '--removable[Attach the image as a removable drive to the virtual machine]' \
    '--firmware[Select the virtual machine firmware to use]:arg:(auto linux linux-noinitrd uefi uefi-secure-boot bios )' \
    '--firmware-variables[Set the path to the firmware variables file to use]' \
    '--linux[Specify the kernel to use for direct kernel boot]' \
    '--drive[Specify drive that mkosi should create and pass to the virtual machine]' \
    '--qemu-args[==SUPPRESS==]' \
    '--register[Register booted vm/container with systemd-machined]' \
    '--storage-target-mode[Run systemd-storagetm as part of the serve verb]' \
    '*::mkosi verb:_mkosi_verb'


