#compdef gear gear-commit gear-srpmimport gear-update gear-import gear-update-tag gear-merge gear-changelog gear-hsh gear-buildreq gear-rpm

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]'
)

local -a opts_gear
opts_gear=(
    '(-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]'
)

local -a opts_gear_compress
opts_gear_compress=(
    '(--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]'
)

local -a opts_gear_update_spec
opts_gear_update_spec=(
	'--update-spec[change specfile in repository if specfile changed]'
)

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

	_arguments -S \
		$opts_help \
		$opts_gear \
		$opts_gear_compress \
		'(--rpmbuild --hasher --command --export-dir --describe --no-compress --bzip2 --gzip :)--export-dir=[write source files to specified directory]:directory:_directories' \
		'(--rpmbuild --hasher --command --export-dir --describe)--hasher[execute hsh-like command afterwards]' \
		'(--rpmbuild --hasher --command --export-dir --describe --no-compress --bzip2 --gzip)--rpmbuild[execute rpmbuild-like command afterwards]' \
		'(--rpmbuild --hasher --command --export-dir --describe)--command[execute arbitrary command afterwards]' \
		'(--rpmbuild --hasher --command --export-dir --no-compress --bzip2 --gzip)--describe[describe package as \"%{NAME} %{VERSION} %{RELEASE}\"]' \
		$args && ret=0
	;;
(gear-commit)
	curcontext="${curcontext%:*:*}:git-commit:"
	service=git-commit
	_arguments -S \
	    '--spec=[spec file]:spec file:_files -g "*.spec(-.)"' \
	    '*:git-commit option: _git' && ret=0
	;;
(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)
	_arguments -S \
		$opts_help \
		'--exclude=[exclude files matching posix-egrep regular expression]:pattern' \
		'--ignore-exclude[ignore .gitignore and .git/info/exclude]' \
		'(-a --all)'{-a,--all}'[extract all files and directories from archive]' \
		'(-c --create)'{-c,--create}'[create the <subdirectory> before unpacking the <source>]' \
		'(-s --subdir)'{-s,--subdir=}'[extract specified directory name from archive]:directory' \
		'(-t --type)'{-t,--type=}'[define source type]:source type:(dir tar cpio cpio.gz cpio.bz2 zip)' \
		'(-f --force)'{-f,--force}'[remove files from <subdirectory> even if untracked or modified files found]' \
		':source:_files' \
		':dst-directory:_directories' && ret=0
	;;
(gear-import)
	_arguments -S \
		$opts_help \
		'(-c --commit -t --tag -T --tag-message -s --sign --no-commit --no-tag --dry-run)--dry-run[show parser results and exit]' \
		'(-c --commit -t --tag -T --tag-message -s --sign --no-commit --no-tag --dry-run)--no-commit[do not commit new changes]' \
		'(-t --tag -T --tag-message --no-tag --dry-run)--no-tag[do not add tag]' \
		'--time=[use time described by STR or referenced by FILE]:time string of file:->time-or-file' \
		'--ignore-exclude[pass --ignore-exclude to gear-update]' \
		'(-C --create)'{-C,--create}'[pass --create to gear-update]' \
		'(-f --force)'{-f,--force}'[pass --force to gear-update]' \
		'(--no-commit --dry-run)'{-s,--sign}'[add sign to commit and tag]' \
		'(-S --subdir)'{-S,--subdir=}'[unpack archives into DIR]:directory:_directories' \
		'(--dry-run --no-commit -c --commit)'{-c,--commit}'[use MSG as commit message]:message' \
		'(--dry-run --no-commit --no-tag -t --tag)'{-t,--tag=}'[use NAME as tag name]:tag name' \
		'(--dry-run --no-commit --no-tag -T --tag-message)'{-T,--tag-message=}'[use MSG as tag message]:tag message' \
		'(-r --rules)'{-r,--rules=}'[override import rules file name]:rules file:_files' \
		'*:archive:_files' && ret=0
	;;
(gear-update-tag)
	_arguments -S \
		$opts_help \
		'(-a --all :)'{-a,--all}'[update all tags used in rules]' \
		'(-c --clean --no-clean :)'{-c,--clean}'[delete tags not used in rules]' \
		'(-c --clean --no-clean)--no-clean[]' \
		'(-d --delete :)'{-d,--delete}'[delete the specified tag]:tag name' \
		'(:)--verify[verify all tags used in rules]' \
		'(-r --rules)'{-r,--rules}'[override rules file name]:rules file:_files' \
		'(-):tag name' \
		'(-):tag value' && ret=0
	;;
(gear-merge)
	_arguments -S \
		$opts_help \
		'(-I --no-interactive)'{-I,--no-interactive}'[merge branches non-interactively]' \
		'(-a --add)'{-a,--add}'[add new patches in git repository]' \
		'(-r --rules)'{-r,--rules}'=[name of file with rules]:rules file:_files' \
		'(-s --stop -I --no-interactive)'{-s,--stop}'=[stop merge when BRANCH shows in <to-branch>]:branch name' \
		'--ignore-changed[do not bail if index changed]' \
		'--ignore-untracked[do not bail if untracked or modified files found]' && ret=0
	;;
(gear-changelog)
	_arguments -S \
		$opts_help \
		'(-r --rules --no-rules)'{-r,--rules}'=[name of a rules file]:rules file:_files' \
		'(-r --rules)--no-rules[do not use rules, write entries without aggregation]' \
		'--no-groups[do not group entries]' \
		'--no-specfile[do not use information from specfile]' \
		'(-f --format)'{-f,--format}'[changelog output format]:format:(rpm gnu deb)' && ret=0
	;;
(gear-hsh)
	_arguments \
		$opts_help \
		$opts_gear \
		$opts_gear_update_spec \
	    '*:hasher option:->hasher' && ret=0
	;;
(gear-buildreq)
	_arguments \
		$opts_help \
		$opts_gear \
		$opts_gear_update_spec \
	    '*:buildreq option:->buildreq' && ret=0
	;;
(gear-rpm)
	_arguments \
		$opts_help \
		$opts_gear \
		$opts_gear_update_spec \
	    '*:rpmbuild option:->rpmbuild' && ret=0
	;;
esac

case $state in
(hasher)
	curcontext="${curcontext%:*:*}:hsh:"
	service=hsh
	_call_function ret _hasher
	;;
(buildreq)
	curcontext="${curcontext%:*:*}:buildreq:"
	service=buildreq
	_call_function ret _buildreq
	;;
(rpmbuild)
	curcontext="${curcontext%:*:*}:rpmbuild:"
	service=rpmb
	_call_function ret _rpm
	;;
(time-or-file)
	_alternative \
		'time-string:time string: ' \
		'files:file:_files' && ret=0
	;;
esac

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