#  bash completion support
#
#  Copyright (C) 2008 Neil Williams <codehelp@debian.org>
#
#  This package is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Remember to always put a space at the end of a line of options.

_emsource()
{
	local cur prev opts cmds help machine arch quiet
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help --version "
	cmds="-c --clean -b --build -p --chroot --where --status "
	arch="-a --arch "
	opts="-u --username --build-dep "
	quiet="--verbose --quiet -v -q "
	machine="-m --machine -V --variant --machine-path "
	COMPREPLY=( $(compgen -W "${arch}${help}${opts}${quiet}${machine}${cmds}" -- ${cur}) )
}
complete -F _emsource emsource

_emchain()
{
	local cur prev opts cmds help arch quiet
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help --version "
	cmds="-f --force -i --ignore -u --uclibc "
	arch="-a --arch "
	quiet="--verbose --quiet -v -q "
	opts="-w --workdir -l --log "
	help="-h -? --help --version "
	COMPREPLY=( $(compgen -W "${arch}${help}${opts}${quiet}${cmds}" -- ${cur}) )
}
complete -F _emchain -o default emchain

_em_autobuild()
{
	local cur prev opts cmds help machine arch
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help --version "
	machine="-m --machine -V --variant --machine-path "
	cmds="-o --omit-current -l --log -p --pbuilder --package "
	arch="-a --arch "
	opts="-e --errexit -s --script -u --handler "
	COMPREPLY=( $(compgen -W "${arch}${machine}${help}${opts}${cmds}" -- ${cur}) )
}
complete -F _em_autobuild -o default em_autobuild

_emdebuild()
{
	local cur prev opts cmds help machine arch quiet
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	help="-h -? --help --version "
	quiet="--verbose --quiet -v -q "
	opts="-n --next --svn --sign --svn-only "
	COMPREPLY=( $(compgen -W "${arch}${help}${opts}${quiet}" -- ${cur}) )
}
complete -F _emdebuild emdebuild

_em_make()
{
	local cur prev opts arch help quiet
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	help="-h -? --help --version "
	quiet="--verbose --quiet -v -q "
	opts="--forceold "
	COMPREPLY=( $(compgen -W "${arch}${help}${quiet}${opts}" -- ${cur}) )
}
complete -F _em_make em_make

_embug()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	cmds="-f --flag -g --get-number -l --list --list-bugs --list-newer \
	-m --missing -r --remove -u --update -o --outdated -d --debian --lintian \
	--failed --prepare -w --waiting "
	help="-h -? --help --version "
	opts="-p --package "
	quiet="--verbose --quiet -v -q "
	COMPREPLY=( $(compgen -W "${cmds}${help}${quiet}${opts}" -- ${cur}) )
}
complete -F _embug embug

_embuildstats()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	help="-h -? --help --version "
	quiet="--verbose --quiet -v -q "
	cmds="-p --pager -c --csv -x --xml -w --html -l --lintian "
	COMPREPLY=( $(compgen -W "${arch}${help}${quiet}${opts}" -- ${cur}) )
}
complete -F _embuildstats embuildstats

_emdebcheck()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	quiet="--verbose --quiet -v -q "
	arch="-a --arch "
	COMPREPLY=( $(
		compgen -G "${cur}*.changes"
		compgen -G "${cur}*.deb"
		compgen -W "${arch}${quiet}${help}" -- ${cur}) )
}
complete -o default -F _emdebcheck emdebcheck

_em_installtdeb()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	opts="--no-act --no-sign "
	COMPREPLY=( $(compgen -W "${arch}${help}${quiet}${opts}" -- ${cur}) )
}
complete -F _em_installtdeb em_installtdeb

_emprunecross()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	help="-h -? --help --version "
	opts="-n --dry-run --simulate"
	COMPREPLY=( $(compgen -W "${arch}${help}${quiet}${opts}" -- ${cur}) )
}
complete -F _emprunecross emprunecross

_emsetup()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	help="-h -? --help --version "
	quiet="--verbose --quiet -v -q "
	opts="-s --simulate --report -y --yes --download "
	COMPREPLY=( $(compgen -W "${arch}${help}${quiet}${opts}" -- ${cur}) )
}
complete -F _emsetup emsetup

_empdebuild()
{
	local cur prev opts cmds help machine arch quiet
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	help="-h -? --help --version "
	cmds="create --create update --update build --build login --login "
	arch="--arch "
	opts=" --testing --save-after-login --login-after-fail --autobuild autobuild "
	COMPREPLY=( $(compgen -W "${arch}${help}${opts}${cmds}" -- ${cur}) )
}
complete -F _empdebuild empdebuild

_emrecent()
{
	local cur prev opts arch help quiet cmds
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	cmds="--noninteractive -r --respawn "
	opts="-t --time -s --skip -w --whiptail -x --exclude-error "
	COMPREPLY=( $(
		compgen -G "${cur}*.changes"
		compgen -W "${arch}${cmds}${quiet}${help}${opts}" -- ${cur}) )
}
complete -o default -F _emrecent emrecent

# emtargetcmp
_emtargetcmp()
{
	local cur prev opts arch help quiet
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	arch="-a --arch "
	help="-h -? --help --version "
	quiet="--verbose --quiet -v -q "
	COMPREPLY=( $(compgen -W "${arch}${help}${quiet}" -- ${cur}) )
}
complete -F _emtargetcmp emtargetcmp
