# file: dcache.sh
# dcache parameter-completion

_dcache ()
{
  local cur

  COMPREPLY=()   # Array variable storing the possible completions.
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"

  if [ ${#COMP_WORDS[@]} -ge 4 ]
  then
   return 0
  fi

  case "$prev" in
	database)
		COMPREPLY=($(compgen -o nospace -W 'ls update tag rollback rollbackToDate listLocks releaseLocks doc' -- "$cur"))
            return 0
            ;;
        dump)
		COMPREPLY=($(compgen -o nospace -W 'heap threads' -- "$cur"))
            return 0
            ;;
        import)
		COMPREPLY=($(compgen -o nospace -W 'hostcert cacerts' -- "$cur"))
            return 0
            ;;
        pool)
		COMPREPLY=($(compgen -o nospace -W 'create reconstruct ls' -- "$cur"))
            return 0
            ;;
        *)
        ;;
    esac

  if [ ${#COMP_WORDS[@]} -ge 3 ]
  then
   return 0
  fi

  COMPREPLY=($(compgen -W 'condrestart restart services check-config start status stop version kpwd database dump import pool' -- "$cur"))
  return 0
}

complete -F _dcache /opt/d-cache/bin/dcache

