# bash completion for krbrelayx                                  -*- shell-script -*-

_krbrelayx()
{
  local cur prev hosts spn_classes
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD - 1]}"
  hosts=$(compgen -A hostname | grep -vE '^(localhost|parrot|ip6-localhost|ip6-loopback|ip6-allnodes|ip6-allrouters|ff02::1|ff02::2|::1|)$')

  if [[ $cur == -* ]]; then
    opts="$(_parse_usage krbrelayx) $(_parse_help krbrelayx --help)"
    COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
  fi
  
  if [[ "$prev" == "-ip" || "$prev" == "--interface-ip" ]]; then
    local ips
    ips=$(ip -o -4 addr show | awk '{print $4}' | cut -d/ -f1)
    COMPREPLY=( $(compgen -W "$ips" -- "$cur") )
    return 0
  fi

  if [[ "$prev" == "-f" || "$prev" == "--format" ]]; then
    COMPREPLY=( $(compgen -W "ccache kirbi" -- "$cur") )
    return 0
  fi

  if [[ "$prev" == "--template" ]]; then
    local templates
    templates="User Machine DomainController"

    COMPREPLY=( $(compgen -W "$templates" -- "$cur") )
    return 0
  fi

}

complete -o bashdefault -o default -F _krbrelayx krbrelayx

# ex: filetype=sh

