# fapolicyd-cli (8) completion                             -*- shell-script -*-

_fapolicydcli()
{
	local cur prev opts
	COMPREPLY=()
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local prev="${COMP_WORDS[COMP_CWORD-1]}"
	local opts="--check-config --check-path --check-status --check-trustdb \
                --check-watch_fs --delete-db --dump-db \
                --file --ftype --help --list --update --reload-rules"

	case $prev in
		--ftype)
			# If bash completions is installed, use it
			if [ -e /usr/share/bash-completion/bash_completion ] ; then
				_filedir
				return 0
			else    # this is almost as good
				compopt -o filenames 2>/dev/null
				COMPREPLY=( $(compgen -f -- ${cur}) )
				return 0
			fi
		;;
		--file) # missing support to suggest files or dirs after these
			# but it's better than nothing
			COMPREPLY=($(compgen -W 'add delete update' -- "$cur"))
			return 0
		;;
	esac

	if [[ $cur == -* ]]; then
		COMPREPLY=($(compgen -W "${opts}" -- "$cur"))
		[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
		return 0
	fi
}

_fapolicyd()
{
	local cur prev opts
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	opts="--debug --debug-deny --help --no-details --permissive"

	if [[ ${cur} == -* ]] ; then
		COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
		return 0
	fi
}

complete -F _fapolicydcli fapolicyd-cli
complete -F _fapolicyd fapolicyd

# ex: filetype=sh
