#compdef gear gear-commit gear-release gear-srpmimport gear-update-archive gear-update-directory

local curcontext="$curcontext" context state line ret=1
typeset -A opt_args

local -a opts_help
opts_help=(
	'(-v --verbose -q --quiet)'{-q,--quiet}'[try to be more quiet]'
	'(-v --verbose -q --quiet)'{-v,--verbose}'[print a message for each action]'
	'(- :)'{-V,--version}'[print program version and exit]'
	'(- :)'{-h,--help}'[show usage and exit]'
)

case "$words[1]" in
(gear)
	local -a args
	args=(':output tarball:_files')
	if (( $words[(I)--rpmbuild] )); then
		args=('--update-spec[change specfile in repository if specfile changed]'
		      '(-):command: _command_names -e'
		      '*::args: _normal')
	elif (( $words[(I)--hasher] )); then
		args=('(-):command: _command_names -e'
		      '*::args: _normal')
	elif (( $words[(I)(--export-dir|--describe)] )); then
		args=()
	fi

	_arguments -S \
		$opts_help \
		'(-r --rules)'{-r,--rules=}'[name of file with rules]:rules file:_files' \
		'(-t --tree-ish --commit)'{-t,--tree-ish=}'[tree, commit or tag object name]:tree-ish' \
		'(-t --tree-ish --commit)--commit[make temporary commit prior to extract]' \
		\
		'(--rpmbuild --export-dir --describe --no-compress --bzip2 --gzip)--no-compress[do not compress output archive]' \
		'(--rpmbuild --export-dir --describe --no-compress --bzip2 --gzip)--bzip2[compress output archive using bzip2]' \
		'(--rpmbuild --export-dir --describe --no-compress --bzip2 --gzip)--gzip[compress output archive using gzip]' \
		\
		'(--rpmbuild --hasher --describe --no-compress --bzip2 --gzip :)--export-dir=[write source files to specified directory]:directory:_directories' \
		'(--rpmbuild --export-dir --describe)--hasher[execute hsh-like command afterwards]' \
		'(--hasher --export-dir --describe --no-compress --bzip2 --gzip)--rpmbuild[execute rpmbuild-like command afterwards]' \
		'(--rpmbuild --hasher --export-dir --no-compress --bzip2 --gzip)--describe[describe package as \"%{NAME} %{VERSION} %{RELEASE}\"]' \
		$args && ret=0
	;;
(gear-commit)
	curcontext="${curcontext%:*:*}:git-commit:"
	words[1]="git-commit"
	_call_function ret _git
	;;
(gear-release)
	_arguments -S \
		$opts_help \
		'--sign=[make a GPG-signed tag]::KEYID' \
		'--create=[create tag before release tag creation]::tag message' \
		'(-n --pkgname)'{-n,--pkgname=}'[add project name to tag message]:project name' \
		'(-t --tags)'{-t,--tags=}'[name of file with release tags]:release tags file:_files' \
		':release-tag:->release-tag' \
		':commit-ish' && ret=0

	case "$state" in
	(release-tag)
		local tagsfile release_tags

		tagsfile="${GIT_DIR:-.git}/gear/release-tags"
		if (( ${+opt_args[--tags]} )); then
			tagsfile="${+opt_args[--tags]}"
		fi
		release_tags=( )
		if [[ -r "$tagsfile" ]]; then
			release_tags=( ${(f)"$(<"$tagsfile")"} )
		fi

		_wanted release-tags expl release-tag \
			compadd $release_tags
		;;
	esac
	;;
(gear-srpmimport)
	_arguments -S \
		$opts_help \
		'--branch=[branch name where to import]:branch' \
		'--import-only[do not perform a checkout after importing]' \
		'--no-untar[do not unpack source tarballs]' \
		'--rules=[name of file with rules]:rules file:_files' \
		'--spec-pattern=[specfile pattern list]:specfile pattern' \
		'(:)--stdin[read source package names from stdin]' \
		'(-)*:source package:_files -g "*.src.rpm"' && ret=0
	;;
(gear-update-archive|gear-update-directory)
	local -a args
	case "$words[1]" in
	(gear-update-archive)
		args=('(-t --tardir)'{-t,--tardir=}'[tar archive directory name]:tar directory:_directories'
		      ':src-archive:_files')
		;;
	(gear-update-directory)
		args=(':src-directory:_directories')
		;;
	esac
	_arguments -S \
		$opts_help \
		'(-f --force)'{-f,--force}'[force update]' \
		$args \
		':dst-directory:_directories' && ret=0
	;;
esac

return $ret
# vim: set ft=zsh ts=4 sw=4 sts=4 :
