# apk(8) completion                                         *- shell-script -*-
# Automatically generated by apk-tools (src/genbash.lua). Do not modify.

# Helpers
__apk_installed_pkgs() { apk query --summarize name --installed "$1*" 2>/dev/null; }
__apk_available_pkgs() { apk query --summarize name --available "$1*" 2>/dev/null; }

_comp_cmd_apk() {
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local applet=""

	# Find the applet (first non-option argument)
	for ((i=1; i < COMP_CWORD; i++)); do
		if [[ ${COMP_WORDS[i]} != -* ]]; then
			applet="${COMP_WORDS[i]}"
			break
		fi
	done

	# Applet specific completion
	case "$applet" in
	adbdump)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--format" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	adbgen)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	adbsign)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--reset-signatures" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	add)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--initdb --latest -l --no-chown --upgrade -u --usermode --virtual -t" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	audit)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--backup --check-permissions --details --full --ignore-busybox-symlinks --packages --protected-paths --recursive -r --system" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	cache)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--add-dependencies --available -a --ignore-conflict --latest -l --upgrade -u --simulate --no-simulate -s" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	convdb)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	convndx)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	del)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--rdepends -r" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_installed_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	dot)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--errors" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	extract)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--destination --no-chown" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	fetch)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--built-after --link -l --pkgname-spec --output -o --simulate --no-simulate -s --stdout -s --url" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	fix)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--depends -d --directory-permissions --reinstall -r --upgrade -u --xattr -x" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_installed_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	index)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--description -d --index -x --merge --no-warnings --output -o --prune-origin --rewrite-arch" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	info)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--all -a --contents -L --depends -R --description -d --exists --installed -e --install-if --license --provides -P --rdepends -r --replaces --rinstall-if --size -s --triggers -t --webpage -w --who-owns -W" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	list)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--available -a --depends -d --installed -I --manifest --origin -o --orphaned -O --providers -P --upgradable --upgradeable -u" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	manifest)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	mkndx)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--description -d --filter-spec --hash --index -x --output -o --pkgname-spec" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	mkpkg)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--compat --files -F --info -I --output -o --rootnode --no-rootnode --script -s --stdout --trigger -t" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	policy)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	query)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--all-matches --available --fields --format --from --installed --match --recursive --summarize --upgradable --world --orphaned" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	search)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--all -a --description -d --exact -e -x --has-origin --origin -o --rdepends -r" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_available_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	stats)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	update)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	upgrade)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--available -a --ignore --latest -l --preupgrade --no-preupgrade --preupgrade-only --prune" -- ${cur}))
		else
			COMPREPLY=($(compgen -W "$(__apk_installed_pkgs "${cur}")" -- ${cur}))
		fi
		;;
	verify)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	version)
		if [[ ${cur} == -* ]]; then
			COMPREPLY=($(compgen -W "--all -a --check -c --indexes -I --limit -l --test -t" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	*)
		if [[ ${cur} == -* ]]; then
			# No applet or unknown applet, complete with global options
			COMPREPLY=($(compgen -W "--allow-untrusted --arch --cache --cache-dir --cache-max-age --cache-packages --cache-predownload --check-certificate --clean-protected --commit-hooks --compression --force --force-binary-stdout --force-broken-world --force-missing-repositories --force-no-chroot --force-non-repository --force-old-apk --force-overwrite --force-refresh --help --initramfs-diskless-boot --interactive[=AUTO] --keys-dir --legacy-info --logfile --network --no-cache --no-cache-packages --no-cache-predownload --no-check-certificate --no-clean-protected --no-commit-hooks --no-legacy-info --no-logfile --no-network --no-preserve-env --no-purge --no-scripts --no-simulate --overlay-from-stdin --preserve-env --pretty-print[=AUTO] --preupgrade-depends --print-arch --progress-fd --progress[=AUTO] --purge --quiet --repositories-file --repository --repository-config --root --root-tmpfs[=AUTO] --scripts --sign-key --simulate --sync[=AUTO] --timeout --update-cache --uvol-manager --verbose --version --wait -C -U -V -X -f -h -p -q -s -v" -- ${cur}))
		elif [[ -z "$applet" ]]; then
			# No applet, complete with applet list
			COMPREPLY=($(compgen -W "adbdump adbgen adbsign add audit cache convdb convndx del dot extract fetch fix index info list manifest mkndx mkpkg policy query search stats update upgrade verify version" -- ${cur}))
		else
			COMPREPLY=()
		fi
		;;
	esac
}

complete -F _comp_cmd_apk apk

