#compdef mph-get

_mph-get () {
	_arguments -s -w \
		'-k[with kernel]' \
		'-n[no execute]' \
		'-v[verbose mode]' \
		'-f[force mode]' \
		'-c[specifies configuration file]:file:_files' \
		'-q[don'\''t update database]' \
		'-x[ignore $holds in mph.conf]' \
		'*::mph-get command:_mph_get_command'
}

(( $+functions[_mph_get_command] )) ||
_mph_get_command () {
	local cmd
	if (( ! $+_mph_get_cmds )); then
		typeset -gA _mph_get_cmds
		_mph_get_cmds=(
			install 	"install package(s)"
			upgrade		"upgrade all installed packages"
			noinstall	"list packages that are not installed"
			noexist		"list packages that are not available anymore"
			whatprovides	"show package which contains given file"
			get		"download package(s)"
			get-all		"download all packages"
			remove		"uninstall package(s)"
			clean		"clean the download cache"
		)
	fi

	if (( CURRENT == 1 )); then
		_tags commands && { compadd "$@" -k _mph_get_cmds }
	else
		local curcontext="$curcontext"
		cmd="${${(k)_mph_get_cmds[(R)* $words[1] *]}:-${(k)_mph_get_cmds[(i)$words[1]]}}"
		if (( $#cmd )); then
			curcontext="${curcontext%:*:*}:mph-${cmd}:"
			case $cmd in
			install | get | remove | whatprovides)
				_mph_get_$cmd
				;;
			*)
				return 0
			esac
		else
			_message "unknown mph command: $words[1]"
		fi
	fi
}

(( $+functions[_mph_get_install] )) ||
_mph_get_install () {
	_arguments -s \
		'*:available packages:_mph_packages install'
}

(( $+functions[_mph_get_get] )) ||
_mph_get_get () {
	_arguments -s \
		'*:available packages:_mph_packages get'
}

(( $+functions[_mph_get_remove] )) ||
_mph_get_remove () {
	_arguments -s \
		'*:installed packages:_mph_packages remove'
}

(( $+functions[_mph_get_whatprovides] )) ||
_mph_get_whatprovides () {
	_arguments -s \
		'*:file:_files'
}
