_enforcer() 
{
	local cur prev opts
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"


	## Tertiery commands
	case "${COMP_WORDS[@]}" in
		*"zone add"*)
			COMPREPLY=( $(compgen -W "--zone --policy --signconf \
				--infile --outfile --intype --outtype --inconf \
				--outconf" -- ${cur}) )
			return 0;;
		*"zone del"*)
			COMPREPLY=( $(compgen -W "--zone --force" -- ${cur}) )
			return 0;;
		*"zone export"*)
			COMPREPLY=( $(compgen -W "--zone" -- ${cur}) )
			return 0;;
		*"key ds-gone"*)
			COMPREPLY=( $(compgen -W "--zone --id --keytag" -- ${cur}) )
			return 0;;
		*"key ds-retract"*)
			COMPREPLY=( $(compgen -W "--zone --id --auto" -- ${cur}) )
			return 0;;
		*"key ds-seen"*)
			COMPREPLY=( $(compgen -W "--zone --id --keytag" -- ${cur}) )
			return 0;;
		*"key ds-submit"*)
			COMPREPLY=( $(compgen -W "--zone --id --auto" -- ${cur}) )
			return 0;;
		*"key export"*)
			COMPREPLY=( $(compgen -W "--zone --dnskey --ds" -- ${cur}) )
			return 0;;
		*"key rollover"*)
			COMPREPLY=( $(compgen -W "--zone --keytype" -- ${cur}) )
			return 0;;
		*"hsm key gen"*)
			COMPREPLY=( $(compgen -W "--duration" -- ${cur}) )
			return 0;;
		*"hsm key list"*)
			COMPREPLY=( $(compgen -W "--verbose" -- ${cur}) )
			return 0;;
	esac

	## Secondary commands
				
	commands="enforce flush help hsm key policy queue reload running \
		setup signconf stop time update verbosity zone"

	local SECONDLEVEL_KEY="ds-gone ds-retract ds-seen ds-submit export list rollover"
	local SECONDLEVEL_HSM="key"
	local SECONDLEVEL_POLICY="list resalt"
	local SECONDLEVEL_TIME="leap"
	local SECONDLEVEL_UPDATE="hsmkeys kasp zonelist"
	local SECONDLEVEL_ZONE="add del export list"
	
	case "${prev}" in
		time)	
			COMPREPLY=( $(compgen -W "${SECONDLEVEL_TIME}" -- ${cur}) )
			return 0;;
		zone)
			COMPREPLY=( $(compgen -W "${SECONDLEVEL_ZONE}" -- ${cur}) )
			return 0;;
		key)
			COMPREPLY=( $(compgen -W "${SECONDLEVEL_KEY}" -- ${cur}) )
			return 0;;
		hsm)
			COMPREPLY=( $(compgen -W "${SECONDLEVEL_HSM}" -- ${cur}) )
			return 0;;
		update)
			COMPREPLY=( $(compgen -W "${SECONDLEVEL_UPDATE}" -- ${cur}) )
			return 0;;
		policy)
			COMPREPLY=( $(compgen -W "${SECONDLEVEL_POLICY}" -- ${cur}) )
			return 0;;
	esac

	COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
	return 0
}

complete -F _enforcer ods-enforcer

### enforce
### flush
### help
### hsm key gen --duration <duration>
### hsm key list --verbose
### key ds-gone --zone <zone> --id <id> --keytag <keytag>
### key ds-retract --zone <zone> --id <id> --auto
### key ds-seen --zone <zone> --id <id> --keytag <keytag>
### key ds-submit --zone <zone> --id <id> --auto
### key export --zone <zone> [--dnskey] [--ds]
### key list
### key rollover --zone <zone> [--keytype <keytype>]
### policy list
### policy resalt
### queue
### reload
### running
### setup
### signconf
### stop
### time leap
### update hsmkeys
### update kasp
### update zonelist
### verbosity <nr>
### zone add --zone <zone> --policy <policy> --signconf <path> --infile <path> --outfile <path> --intype <type> --outtype <type> --inconf <path> --outconf <path>
### zone del --zone <zone> --force
### zone export --zone <zone>
### zone list
