# Bash completion for t2fuzz

_t2fuzz() {
    local cur prev words cword

    if type -t _init_completion &> /dev/null; then
        _init_completion -n = || return
    else
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
    fi

    case "$prev" in
        -s|--start|-t|--stop|-p|--step|-a|--addr|--address|-P|--port)
            return
            ;;
        -w|--outpref|--output-prefix)
            if type -t _filedir &> /dev/null; then
                _filedir
            else
                compopt -o filenames 2> /dev/null
                COMPREPLY=($(compgen -f -- "$cur"))
            fi
            return
            ;;
    esac

    local args=(
        -s --start
        -t --stop
        -p --step
        -w --outpref --output-prefix
        -S --socket
        -a --addr --address
        -P --port
        -d --debug
        -v --verbose
        -h --help
    )

    if [[ "$cur" == -* ]]; then
        COMPREPLY=($(compgen -W "${args[*]}" -- "$cur"))
        #COMPREPLY=($(compgen -W "$(_parse_help "$T2HOME/scripts/t2fuzz")" -- "$cur"))
    elif type -t _filedir &> /dev/null; then
        _filedir
    else
        compopt -o filenames 2> /dev/null
        COMPREPLY=($(compgen -f -- "$cur"))
    fi
}

complete -F _t2fuzz t2fuzz
