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

_check_homeassistant_sensor()
{
    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 | --host | --time-server)
            mapfile -t COMPREPLY < <(compgen -A hostname -- "$cur")
            return
            ;;
        -f | --token-file | --ca-cert)
            compopt -o filenames 2>/dev/null
            mapfile -t COMPREPLY < <(compgen -f -- "$cur")
            return
            ;;
        --check)
            mapfile -t COMPREPLY < <(compgen -W 'sensor time age binary text compare' -- "$cur")
            return
            ;;
        --unavailable-state)
            mapfile -t COMPREPLY < <(compgen -W 'ok warning critical unknown' -- "$cur")
            return
            ;;
        --true-state | --false-state | --match-state | --no-match-state)
            mapfile -t COMPREPLY < <(compgen -W 'ok warning critical' -- "$cur")
            return
            ;;
        --must-be)
            mapfile -t COMPREPLY < <(compgen -W 'above below' -- "$cur")
            return
            ;;
        --age-of)
            mapfile -t COMPREPLY < <(compgen -W 'reported updated changed' -- "$cur")
            return
            ;;
        -p | --port | -t | --timeout | -T | --token | --entity | --attribute | \
            -w | --warning | -c | --critical | --uom | --compare-entity | \
            --compare-attribute | --binary-expr | --regex)
            return
            ;;
    esac

    # no positional arguments: offer the options
    mapfile -t COMPREPLY < <(compgen -W '-h --help -V --version -H --host -p --port
        -S --ssl --insecure --ca-cert -t --timeout -f --token-file -T --token
        --list --check --entity --attribute --unavailable-state -w --warning
        -c --critical --uom --time-server --compare-entity --compare-attribute
        --must-be --age-of --binary-expr --true-state --false-state --regex
        -i --ignore-case --match-state --no-match-state' -- "$cur")
}
complete -F _check_homeassistant_sensor check_homeassistant_sensor
