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

_check_flexlm_server()
{
    local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
    # --option=value: bash splits at the =
    if [[ $cur == = ]]; then
        cur=
    elif [[ $prev == = && $COMP_CWORD -ge 2 ]]; then
        prev=${COMP_WORDS[COMP_CWORD-2]}
    fi
    COMPREPLY=()

    case $prev in
        -H | --hostname)
            mapfile -t COMPREPLY < <(compgen -A hostname -- "$cur")
            return
            ;;
        -s | --ssh)
            # [USER@]HOST
            local user=
            [[ $cur == *@* ]] && user=${cur%%@*}@
            mapfile -t COMPREPLY < <(compgen -A hostname -P "$user" -- "${cur#*@}")
            return
            ;;
        -l | --lmutil)
            compopt -o filenames 2>/dev/null
            mapfile -t COMPREPLY < <(compgen -f -- "$cur")
            return
            ;;
        -p | --port | -w | --warning | -c | --critical | -t | --timeout)
            return
            ;;
    esac

    # no positional arguments: offer the options
    mapfile -t COMPREPLY < <(compgen -W '-h --help -V --version -l --lmutil
        -H --hostname -p --port -w --warning -c --critical -t --timeout
        -s --ssh' -- "$cur")
}
complete -F _check_flexlm_server check_flexlm_server
