#compdef dispass

local expl
local -a dispass_labels _dispass_commands

get_labels_all() {
  if [[ "$state" == labels ]]; then
    dispass_labels=(${(f)"$(_call_program dispass_labels \
        dispass list --all --script | awk '{ print $1 }' 2>/dev/null)"})
    _wanted dispass_labels expl 'all labels' compadd -a dispass_labels
  fi
}
get_labels_enabled() {
  if [[ "$state" == labels ]]; then
    dispass_labels=(${(f)"$(_call_program dispass_labels \
        dispass list --script | awk '{ print $1 }' 2>/dev/null)"})
    _wanted dispass_labels expl 'all labels' compadd -a dispass_labels
  fi
}

_dispass_commands=(
  'add:add a new label to labelfile'
  'disable:disable a label without throwing it away'
  'enable:enable a label'
  'generate:generate passphrases for one or more labels'
  'gui:start the graphical version of DisPass'
  'help:show help information'
  'increment:increment the sequence number of a label'
  'list:print a formatted table of labelfile contents'
  'remove:remove label from labelfile'
  'update:update information for a label'
  'version:show full version information'
)

_arguments \
  '(-h --help -f --file -V --version)-f+[override labelfile]:path to labelfile:_files' \
  '(-h --help -f --file -V --version)--file+[override labelfile]:path to labelfile:_files' \
  '(-h --help -f --file -V --version)-h[show help information]' \
  '(-h --help -f --file -V --version)--help[show help information]' \
  '(-h --help -f --file -V --version)-V[show full version information]' \
  '(-h --help -f --file -V --version)--version[show full version information]' \
  '*:: :->subcmds' && return 0

if (( CURRENT == 1 )); then
  _describe -t commands "dispass command" _dispass_commands
  return
fi

case "$words[1]" in
  a*)
    _arguments \
      '(-i --interactive -h --help -n --dry-run -s --silent)-i[add label in an interactive manner]' \
      '(-i --interactive -h --help -n --dry-run -s --silent)--interactive[add label in an interactive manner]' \
      '(-g --generate -h --help -n --dry-run -s --silent)-g[immediately generate passphrase after adding it]' \
      '(-g --generate -h --help -n --dry-run -s --silent)--generate[immediately generate passphrase after adding it]' \
      '(-i --interactive -g --generate -h --help -n --dry-run -s --silent)-h[show help information]' \
      '(-i --interactive -g --generate -h --help -n --dry-run -s --silent)--help[show help information]' \
      '(-i --interactive -g --generate -h --help -n --dry-run)-n[do not actually add label to labelfile]' \
      '(-i --interactive -g --generate -h --help -n --dry-run)--dry-run[do not actually add label to labelfile]' \
      '(-i --interactive -h --help -s --silent)-s[do not print success message]' \
      '(-i --interactive -h --help -s --silent)--silent[do not print success message]' \
      &&  return 0 ;;
  d* | i* | u*)
    _arguments \
      '(-n --dry-run -s --silent)-h[show help information]' \
      '(-n --dry-run -s --silent)--help[show help information]' \
      '(-h --help -n --dry-run)-n[do not actually update label in labelfile]' \
      '(-h --help -n --dry-run)--dry-run[do not actually update label in labelfile]' \
      '(-h --help -s --silent)-s[do not print success message]' \
      '(-h --help -s --silent)--silent[do not print success message]' \
      '*:: :->labels' && return 0
    get_labels_enabled ;;
  e*)
    _arguments \
      '(-n --dry-run -s --silent)-h[show help information]' \
      '(-n --dry-run -s --silent)--help[show help information]' \
      '(-h --help -n --dry-run)-n[do not actually update label in labelfile]' \
      '(-h --help -n --dry-run)--dry-run[do not actually update label in labelfile]' \
      '(-h --help -s --silent)-s[do not print success message]' \
      '(-h --help -s --silent)--silent[do not print success message]' \
      '*:: :->labels' && return 0
    get_labels_all ;;
  ge*)
    _arguments \
      '(-h --help)-h[show help information]' \
      '(-h --help)--help[show help information]' \
      '(-h --help -v --verify)-v[verify password]' \
      '(-h --help -v --verify)--verify[verify password]' \
      '(-h --help -l --length)-l+[length of passphrase]:passphrase length:' \
      '(-h --help -l --length)--length+[length of passphrase]:passphrase length:' \
      '(-h --help -a --algo)-a+[algorithm to use for generation]:algorithm:(dispass1 dispass2)' \
      '(-h --help -a --algo)--algo+[algorithm to use for generation]:algorithm:(dispass1 dispass2)' \
      '(-h --help -s --seqno)-s+[sequence number to use for generation]:sequence number:' \
      '(-h --help -s --seqno)--seqno+[sequence number to use for generation]:sequence number:' \
      '(-h --help -p --password)-p+[password to use for generation]:password:' \
      '(-h --help -p --password)--password+[password to use for generation]:password:' \
      '(-h --help -o --output)-o[output passphrase(s) directly to stdout]' \
      '(-h --help -o --output)--output[output passphrase(s) directly to stdout]' \
      '(-h --help --silent)--silent[do not show a prompt when errors occur]' \
      '*:: :->labels' && return 0
    get_labels_enabled ;;
  gu*)
    _arguments \
      '(-h --help)-h[show help information]' \
      '(-h --help)--help[show help information]' \
      &&  return 0 ;;
  h*)
    _describe -t commands "dispass subcommands" _dispass_commands
    return 0 ;;
  l*)
    _arguments \
      '(-h --help -n --names-only --script)-h[show help information]' \
      '(-h --help -n --names-only --script)--help[show help information]' \
      '(-h --help -n --names-only --script)-n[only print names of the labels]' \
      '(-h --help -n --names-only --script)--names-only[only print names of the labels]' \
      '(-h --help -n --names-only --script)--script[output in fixed columns]' \
      &&  return 0 ;;
  r*)
    _arguments \
      '(-i --interactive -h --help -n --dry-run -s --silent)-i[remove label in an interactive manner]' \
      '(-i --interactive -h --help -n --dry-run -s --silent)--interactive[remove label in an interactive manner]' \
      '(-i --interactive -h --help -n --dry-run -s --silent)-h[show help information]' \
      '(-i --interactive -h --help -n --dry-run -s --silent)--help[show help information]' \
      '(-i --interactive -h --help -n --dry-run)-n[do not actually remove label from labelfile]' \
      '(-i --interactive -h --help -n --dry-run)--dry-run[do not actually remove label from labelfile]' \
      '(-i --interactive -h --help -s --silent)-s[do not print success message]' \
      '(-i --interactive -h --help -s --silent)--silent[do not print success message]' \
      '*:: :->labels' && return 0
    get_labels_all ;;
  v*)
    return 0
esac

# vim: set ft=zsh et ts=2 sw=2 sts=2:
