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

_check_rapl()
{
    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
        --state-file)
            mapfile -t COMPREPLY < <(compgen -f -- "$cur")
            return
            ;;
        -w | --warning | -c | --critical | -i | --interval | --max-age)
            return
            ;;
    esac

    local options='-h --help -V --version -w --warning -c --critical -i --interval
        --max-age --state-file --no-state -v --verbose'
    mapfile -t COMPREPLY < <(compgen -W "$options" -- "$cur")
}
complete -F _check_rapl check_rapl
