#!/bin/bash
# SPDX-FileCopyrightText: 2026 Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
# SPDX-License-Identifier: GPL-2.0-or-later

_sbuild_complete() {
	SWITCHES="--help --version --verbose --quiet --debug --arch-all --dist \
	--chroot --chroot-mode --arch --arch-any --no-arch-any --build --host \
	--profiles --source --force-orig-source --make-binNMU --binNMU \
	--append-to-version --binNMU-timestamp --binNMU-changelog --build-dir \
	--add-depends --add-conflicts --add-depends-arch --add-conflicts-arch \
	--add-depends-indep --add-conflicts-indep --maintainer --uploader \
	--keyid --source-only-changes --no-source-only-changes --jobs \
	--debbuildopt --deb‐buildopts --dpkg-source-opt --dpkg-source-opts \
	--dpkg-file-suffix --purge --purge-build --purge-deps --purge-session \
	--batch --nolog --hide-log-sections --clean-source --no-clean-source \
	--run-lintian --no-run-lintian --lintian-opt --lintian-opts --run-piuparts \
	--no-run-piuparts --piuparts-opt --piuparts-opts --piuparts-root-arg \
	--piuparts-root-args--run-autopkgtest --no-run-autopkgtest \
	--autopkgtest-opt --autopkgtest-opts --autopkgtest-root-arg \
	--autopkgtest-root-args --pre-build-commands --chroot-setup-commands \
	--chroot-update-failed-commands --build-deps-failed-commands \
	--starting-build-commands --finished-build-commands \
	--build-failed-commands --chroot-cleanup-commands --post-build-commands \
	--post-build-failed-commands --anything-failed-commands \
	--log-external-command-output --log-external-command-error --setup-hook \
	--build-dep-resolver --resolve-alternatives --no-resolve-alternatives \
	--extra-package --extra-repository --extra-repository-key --build-path \
	--dsc-dir --autopkgtest-virt-server --autopkgtest-virt-server-opt \
	--autopkgtest-virt-server-opts --purge-extra-packages \
	--bd-uninstallable-explainer"

	cur="${COMP_WORDS[COMP_CWORD]}"      # Partially written argument
	prev="${COMP_WORDS[COMP_CWORD - 1]}" # Previously written argument

	if [[ $prev == "--dist" ]]; then
		COMPREPLY=($(compgen -W "unstable testing" -- ${cur}))
		return 0
	elif [[ $prev == "--chroot-mode" ]]; then
		COMPREPLY=($(compgen -W "schroot sudo autopkgtest unshare" -- ${cur}))
		return 0
	elif [[ $prev == "--bd-uninstallable-explainer" ]]; then
		COMPREPLY=($(compgen -W "dose3 apt none" -- ${cur}))
		return 0
	fi

	#TODO
	# --chroot=chroot
	# --build-dir=directory
	# --setup-hook=hook-script
	# --extra-repository-key=file.asc
	# --extra-package=package.deb|directory

	COMPREPLY=($(compgen -W "$SWITCHES" -- ${cur}))
}

complete -F _sbuild_complete sbuild
