#!/bin/bash
# dselect(8) bash completion
#
# Copyright © 2002 Ian Macdonald <ian@caliban.org>
# Copyright © 2003 Ariel Fermani <the_end@bbs.frc.utn.edu.ar>
# Copyright © 2009 Guillaume Rousse <rousse@ccr.jussieu.fr>
# Copyright © 2009-2010 David Paleino <dapal@debian.org>
# Copyright © 2009-2023 Ville Skyttä <ville.skytta@iki.fi>
# Copyright © 2022-2023 Koichi Murase <myoga.murase@gmail.com>
# Copyright © 2026 Guillem Jover <guillem@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

_comp_cmd_dselect()
{
  # shellcheck disable=SC2034
  local cur prev words cword comp_args
  _comp_initialize -- "$@" || return

  case $prev in
  --admindir | \
  --instdir | \
  --root)
    _comp_compgen_filedir -d
    return
    ;;
  --debug | -D)
    _comp_compgen_filedir
    return
    ;;
  esac

  if [[ $cur == -* ]]; then
    _comp_compgen_help
  else
    declare -a commands
    commands=(
      access
      update
      select
      install
      config
      remove
      quit
    )
    _comp_compgen -- -W "${commands[*]}"
  fi
} && complete -F _comp_cmd_dselect dselect
