#compdef archbuild archco arch-nspawn archrelease commitpkg finddeps makechrootpkg mkarchroot rebuildpkgs extrapkg=commitpkg corepkg=commitpkg testingpkg=commitpkg stagingpkg=commitpkg communitypkg=commitpkg community-testingpkg=commitpkg community-stagingpkg=commitpkg multilibpkg=commitpkg multilib-testingpkg=commitpkg extra-x86_64-build=archbuild testing-x86_64-build=archbuild staging-x86_64-build=archbuild multilib-build=archbuild multilib-testing-build=archbuild multilib-staging-build=archbuild kde-unstable-x86_64-build=archbuild gnome-unstable-x86_64-build=archbuild communityco=archco checkpkg sogrep offload-build
# License: Unspecified

#!/hint/bash
# License: Unspecified
:

# shellcheck disable=2034
_arch=(
	x86_64
	any
)

# shellcheck disable=2034
_tags=(
	core-x86_64 core-any
	extra-x86_64 extra-any
	multilib-x86_64
	staging-x86_64 staging-any
	testing-x86_64 testing-any
	multilib-testing-x86_64
	multilib-staging-x86_64
	community-x86_64 community-any
	community-staging-x86_64 community-staging-any
	community-testing-x86_64 community-testing-any
	kde-unstable-x86_64 kde-unstable-any
	gnome-unstable-x86_64 gnome-unstable-any
)

#!/hint/bash
# License: Unspecified
:

# shellcheck disable=2034
_repos=(
	staging
	testing
	core
	extra
	community-staging
	community-testing
	community
	multilib-staging
	multilib-testing
	multilib
	gnome-unstable
	kde-unstable
)

# shellcheck disable=2034
_build_repos=(
	staging
	testing
	extra
	multilib-staging
	multilib-testing
	multilib
	gnome-unstable
	kde-unstable
)


_binary_arch=${_arch[*]:0:-1}

_archbuild_args=(
	'-c[Recreate the chroot before building]'
	'-r[Create chroots in this directory]:base_dir:_files -/'
	'-h[Display usage]'
)

_archco_args=(
	'*:packages:_devtools_completions_all_packages'
)

_arch_nspawn_args=(
	'-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"'
	'-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"'
	'-c[Set pacman cache]:pacman_cache:_files -/'
	'-f[Copy file from the host to the chroot]:copy_file:_files'
	'-s[Do not run setarch]'
	'-h[Display usage]'
	'1:chroot_dir:_files -/'
)

_archrelease_args=(
	'-f[Force release without checks]'
	"*:arch:($_tags[*])"
)

_commitpkg_args=(
	'-f[Force release without checks]'
	'-s[Target repo server]'
	'-l[Set bandwidth limit]:limit'
	"-a[Release to a specific architecture only]:arch:($_arch[*])"
	'1:commit_msg'
)

_finddeps_args=(
	'1:packages:_devtools_completions_all_packages'
)

_makechrootpkg_args=(
	'-h[Display usage]'
	'-c[Clean the chroot before building]'
	'-d[Bind directory into build chroot as read-write]:bind_dir_rw:_files -/'
	'-D[Bind directory into build chroot as read-only]:bind_dir_ro:_files -/'
	'-u[Update the working copy of the chroot before building]'
	'-r[The chroot dir to use]:chroot_dir:_files -/'
	'-I[Install a package into the working copy]:target:_files -g "*.pkg.tar.*(.)"'
	'-l[The directory to use as the working copy]:copy_dir:_files -/'
	'-n[Run namcap on the package]'
	'-T[Build in a temporary directory]'
	'-U[Run makepkg as a specified user]:makepkg_user'
)

_mkarchroot_args=(
	'-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"'
	'-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"'
	'-c[Set pacman cache]:pacman_cache:_files -/'
	'-h[Display usage]'
	'1:working_dir:_files -/'
	'*:packages:_devtools_completions_all_packages'
)

_rebuildpkgs_args=(
	'1:chroot_dir:_files -/'
	'*:packages:_devtools_completions_all_packages'
)

_checkpkg_args=(
	'(-r --rmdir)'{-r,--rmdir}'[Remove the temporary directory]'
	'(-w --warn)'{-w,--warn}'[Print a warning in case of differences]'
	'(-h --help)'{-h,--help}'[Display usage]'
)

_sogrep_args=(
	'(-v --verbose)'{-v,--verbose}'[Show matched links in addition to pkgname]'
	'(-r --refresh)'{-r,--refresh}'[Refresh the links databases]'
	'(-h --help)'{-h,--help}'[Display usage]'
	'1:repo:(all $_repos[*])'
	'2:libname'
)

_offload_build_args=(
	'(-r --repo)'{-r,--repo}'[Build against a specific repository]:repo:($_build_repos[*])'
	'(-a --arch)'{-a,--arch}'[Build against a specific architecture]:arch:(${_binary_arch[*]})'
	'(-s --server)'{-s,--server}'[Offload to a specific Build server]:server:'
	'(-h --help)'{-h,--help}'[Display usage]'
)

_devtools_completions_all_packages() {
	typeset -U packages
	packages=($(_call_program packages pacman -Sql))
	compadd - "${(@)packages}"
}

_devtools() {
	local argname="_${service//-/_}_args[@]"
	_arguments -s "${(P)argname}"
}

_devtools
