# Debian uecorebuilder(8) completion.

have uecorebuilder &&
_uecorebuilder() 
{
	dashify()
	{
		local i

		for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
			if [ ${#COMPREPLY[i]} -le 2 ]; then
				COMPREPLY[i]=-${COMPREPLY[i]}
			else
				COMPREPLY[i]=--${COMPREPLY[i]}
			fi
		done
	}

	local cur cur_nodash prev

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	cur_nodash=${cur#-}
	prev=${COMP_WORDS[COMP_CWORD-1][COMP_CWORD-2]}

	if [ $COMP_CWORD = 1 ]; then
		# first parameter on line
		case "$cur" in
		-b*)
			COMPREPLY=( $( compgen -W 'build' \
				       $cur_nodash ) )
			dashify
			return 0
			;;
		-h*)
			COMPREPLY=( $( compgen -W 'help' \
				       $cur_nodash ) )
			dashify
			return 0
			;;
		-v*)
			COMPREPLY=( $( compgen -W 'version' \
				       $cur_nodash ) )
			dashify
			return 0
			;;
		--*)
			COMPREPLY=( $( compgen -W 'build help version' ${cur_nodash#-} ) )
			dashify;
			return 0
			;;
		*)
			COMPREPLY=( $( compgen -W 'b h v' \
				       $cur_nodash ) )
			dashify
			return 0
			;;
		esac
	fi
	if [ $COMP_CWORD = 2 ]; then
		case "${COMP_WORDS[1]}" in
		--b*)
			# standard filename completion
			COMPREPLY=( $( compgen -W "3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7" $cur ) )
			# COMPREPLY=( $( compgen -G $cur\*.iso ) )
			return 0
			;;
		-b)
			# standard filename completion
			COMPREPLY=( $( compgen -W "3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7" $cur ) )
			return 0
			;;
		--h*)
			# complete on list of relevant options
			COMPREPLY=( $( compgen -W 'build help version' ${cur_nodash#-} ) )
			#dashify;
			return 0
			;;
		-h)
			# complete on list of relevant options
			COMPREPLY=( $( compgen -W 'build help version' ${cur_nodash#-} ) )
			#dashify;
			return 0
			;;
		esac
	fi
	case "${COMP_WORDS[2]}" in
	build)
		# standard filename completion
		COMPREPLY=( $( compgen -W '--defaultde=' ${cur_nodash#-} ) )
		return 0
		;;
	esac
}
complete -F _uecorebuilder uecorebuilder
