#/usr/bin/env bash
_zpc_completions() {
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD - 1]}"

  case $prev in
  --zpc.serial)
    local ttys=$(echo /dev/tty*)
    COMPREPLY=($(compgen -W "$ttys" -- $cur))
    return 0
    ;;
  --zpc.rf_region)
    COMPREPLY=($(compgen -W "EU US ANZ HK IN IL RU CN JP KR" -- $cur))
    return 0
    ;;
  esac

  case $cur in
  -*)
    local suggestions=$(${COMP_WORDS[0]} --help | grep "  --" | awk '{printf "%s\n", $1}')

    COMPREPLY=($(compgen -W "$suggestions" -- "${cur}"))
    return 0
    ;;
  esac
  compopt -o bashdefault
  COMPREPLY=($(compgen -f -- $cur))
  return 0
}

complete -F _zpc_completions -o nospace zpc
