# @generated by usage-argv for `usage __complete_word__ --shell bash`

_usage_complete_usage() {
    local __usage_out __usage_line __usage_files= __usage_extensions= __usage_prefix= __usage_quoted=
    # Truncated here rather than passed with an offset: every shell counts a cursor in its own
    # units — characters in a UTF-8 locale for bash and zsh, characters for fish and PowerShell —
    # and a number that means one thing here and another there is a bug waiting for a non-ASCII
    # command line. Cut with the shell's own offset, the units cancel out and what arrives is
    # exactly the text before the cursor.
    __usage_out="$(command 'usage' __complete_word__ --shell bash \
        --line "${COMP_LINE:0:$COMP_POINT}" \
        --bash-word "${COMP_WORDS[COMP_CWORD]}" \
        --bash-wordbreaks "$COMP_WORDBREAKS" 2>/dev/null)" || return 1

    COMPREPLY=()
    while IFS= read -r __usage_line; do
        case "$__usage_line" in
            $'\001files') __usage_files=any ;;
            $'\001dirs') __usage_files=dirs ;;
            $'\001executables') __usage_files=executables ;;
            $'\001commands') __usage_files=commands ;;
            $'\001extensions\t'*)
                __usage_files=extensions
                __usage_extensions="${__usage_line#*$'\t'}"
                ;;
            $'\001prefix\t'*) __usage_prefix="${__usage_line#*$'\t'}" ;;
            $'\001quoted') __usage_quoted=1 ;;
            '') ;;
            *) COMPREPLY+=("$__usage_line") ;;
        esac
    done <<< "$__usage_out"

    if [[ -n $__usage_files ]]; then
        # Set here rather than on `complete`, because whether this position takes a path is not
        # known until the answer comes back. It is what makes bash append a `/` to a directory
        # and stop escaping what it should not.
        [[ $__usage_files == commands ]] || compopt -o filenames 2>/dev/null
        local __usage_cur="${COMP_WORDS[COMP_CWORD]}" __usage_path
        local -a __usage_paths=()
        if [[ $__usage_files == commands ]]; then
            while IFS= read -r __usage_path; do __usage_paths+=("$__usage_path"); done \
                < <(compgen -c -- "$__usage_cur")
        elif [[ $__usage_files == executables ]]; then
            while IFS= read -r __usage_path; do
                [[ -d "$__usage_path" || -x "$__usage_path" ]] && __usage_paths+=("$__usage_path")
            done < <(compgen -f -- "$__usage_cur")
        elif [[ $__usage_files == dirs ]]; then
            while IFS= read -r __usage_path; do __usage_paths+=("$__usage_path"); done \
                < <(compgen -d -- "$__usage_cur")
        else
            while IFS= read -r __usage_path; do
                if [[ $__usage_files != extensions || -d "$__usage_path" ]]; then
                    __usage_paths+=("$__usage_path")
                    continue
                fi
                local __usage_extension
                while IFS= read -r __usage_extension; do
                    [[ "$__usage_path" == *."$__usage_extension" ]] && {
                        __usage_paths+=("$__usage_path")
                        break
                    }
                done < <(tr '\t' '\n' <<< "$__usage_extensions")
            done < <(compgen -f -- "$__usage_cur")
        fi
        # Guarded, because an empty array expands to one empty word in older bash.
        (( ${#__usage_paths[@]} )) && COMPREPLY+=("${__usage_paths[@]}")
    fi

    # Decided before the prefix is trimmed, so a candidate that is nothing but the prefix
    # (`node@`) is still seen as one meant to be continued.
    # A bare `complete -F` appends a space to every candidate, which is wrong for one meant to be
    # continued (`node@`, `build:`, `sub/`, `--shell=`). So the space is ours: appended to the
    # finished candidates only, with `nospace` on (inside an open quote, Readline keeps its own space unless every candidate is partial). Not when paths are offered, where `filenames`
    # does its own suffixing and would escape a space added here.
    if [[ -z $__usage_files ]]; then
        local __usage_j __usage_open=1
        for __usage_j in "${!COMPREPLY[@]}"; do
            [[ ${COMPREPLY[__usage_j]} == *[@:/=] ]] || __usage_open=
        done
        if [[ -z $__usage_quoted ]]; then
            compopt -o nospace 2>/dev/null
            # Only at the end of the line, as Readline does: mid-word a space would split it.
            if (( COMP_POINT == ${#COMP_LINE} )); then
                for __usage_j in "${!COMPREPLY[@]}"; do
                    [[ ${COMPREPLY[__usage_j]} == *[@:/=] ]] || COMPREPLY[__usage_j]+=' '
                done
            fi
        elif [[ -n $__usage_open ]] && (( ${#COMPREPLY[@]} )); then
            # Readline closes the quote and adds its own space after a finished value, which is
            # right. Only when every candidate is meant to be continued is the space unwanted.
            compopt -o nospace 2>/dev/null
        fi
    fi

    # Readline replaces only the text after a colon when `:` is in COMP_WORDBREAKS. The binary
    # split the original line without losing that prefix, so remove it from full candidates before
    # Readline inserts them. Candidates produced locally for paths do not carry it and stay intact.
    if [[ -n $__usage_prefix ]]; then
        local __usage_i
        for __usage_i in "${!COMPREPLY[@]}"; do
            [[ ${COMPREPLY[__usage_i]} == "$__usage_prefix"* ]] &&
                COMPREPLY[__usage_i]="${COMPREPLY[__usage_i]#"$__usage_prefix"}"
        done
    fi
}
complete -F _usage_complete_usage 'usage'
