# Debian dupload(1) completion
#
# Copyright © 2002 Roland Mas <lolando@debian.org>
# Copyright © 2009 Paul Evans <leonerd@leonerd.org.uk>
# Copyright © 2017-2023 Guillem Jover <guillem@debian.org>

_dupload()
{
  COMPREPLY=()

  local cur=${COMP_WORDS[COMP_CWORD]}
  local prev=${COMP_WORDS[COMP_CWORD-1]}
  local options=(
    -c --configfile
    -d --debug
    -f --force
    -k --keep
    --no
    --nostats
    --nomail
    --mta
    --mailonly
    --noarchive
    -p --print
    -q --quiet
    -t --to
    -V --Version
  )

  case $cur in
  -*)
    COMPREPLY=($(compgen -W "${options[*]}" -- "$cur"))
    return
    ;;
  esac

  case $prev in
  --no|--nomail|--noarchive|\
  -k|--keep|\
  -d|--debug|\
  -f|--force|\
  -p|--print|\
  -q|--quiet|\
  -V|--Version)
    return
    ;;
  --configfile|-c|--mta)
    COMPREPLY=($(compgen -G "$cur*"))
    compopt -o filenames
    ;;
  --to)
    declare -a nicknames
    nicknames=($(dupload -p | awk -F': ' '/nick name/ { print $2 }'))
    COMPREPLY=($(compgen -W "${nicknames[*]}" -- "$cur"))
    ;;
  *)
    COMPREPLY=($(
      compgen -G "${cur}*.changes"
      compgen -W "${options[*]}" -- "$cur"
    ))
    compopt -o filenames
    compopt -o plusdirs
    ;;
  esac

  return
}
complete -F _dupload dupload

# vi: filetype=bash
