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

_check_mqtt_topic_age()
{
    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
        --db-filename)
            compopt -o filenames 2>/dev/null
            mapfile -t COMPREPLY < <(compgen -f -- "$cur")
            return
            ;;
        --mode)
            mapfile -t COMPREPLY < <(compgen -W 'age count' -- "$cur")
            return
            ;;
        -w | --warning | -c | --critical | --mqtt-topic | --window | -t | --timeout)
            return
            ;;
    esac

    # no positional arguments: offer the options
    mapfile -t COMPREPLY < <(compgen -W '-h --help -V --version -w --warning
        -c --critical --db-filename --mqtt-topic --mode --window --per-topic
        -t --timeout' -- "$cur")
}
complete -F _check_mqtt_topic_age check_mqtt_topic_age
