
# shellcheck shell=bash

# Check for bash
[ -z "$BASH_VERSION" ] && return

####################################################################################################

__dconf() {
  local choices

  case "${COMP_CWORD}" in
    1)
      choices=$'help \nread \nlist \nlist-locks \nwrite \nreset \ncompile \nupdate \nwatch \ndump \nload \nblame '
      ;;

    2)
      case "${COMP_WORDS[1]}" in
        help)
          choices=$'help \nread \nlist \nlist-locks \nwrite \nreset \ncompile \nupdate \nwatch \ndump \nload \nblame '
          ;;
        list|list-locks|dump|load)
          choices="$("$1" _complete / "${COMP_WORDS[2]}")"
          ;;
        read|write|lock|unlock|watch|reset)
          choices="$("$1" _complete '' "${COMP_WORDS[2]}")"
          ;;
      esac
      ;;

    3)
      case "${COMP_WORDS[1]} ${COMP_WORDS[2]}" in
	reset\ -f)
          choices="$("$1" _complete '' "${COMP_WORDS[3]}")"
          ;;
      esac
      ;;
  esac

  local IFS=$'\n'
  # shellcheck disable=SC2207
  COMPREPLY=($(compgen -W "${choices-}" -- "${COMP_WORDS[$COMP_CWORD]}"))
}

####################################################################################################

complete -o nospace -F __dconf dconf
