# @generated by usage-cli from usage spec
# Requires bash-completion (https://github.com/scop/bash-completion), which must be
# sourced before this script.
_usage() {
    if ! type -P usage &> /dev/null; then
        echo >&2
        echo "Error: usage CLI not found. This is required for completions to work in usage." >&2
        echo "See https://usage.jdx.dev for more information." >&2
        return 1
    fi
    if ! declare -F _init_completion > /dev/null 2>&1; then
        echo >&2
        echo "Error: bash-completion is required for usage completions but was not loaded." >&2
        echo "Install it from your package manager and source it before this script." >&2
        return 1
    fi

	local cur prev words cword comp_args
    _init_completion -n : -- "$@" || return
    local spec_dir="${XDG_CACHE_HOME:-$HOME/.cache}/usage"
    [[ -d "$spec_dir" ]] || mkdir -p -m 700 "$spec_dir"
    local spec_file="$spec_dir/usage__usage_spec_usage.spec"
    command usage --usage-spec >| "$spec_file"
    # shellcheck disable=SC2207
	COMPREPLY=($(compgen -W "$(command usage complete-word --shell bash -f "$spec_file" --cword="$cword" -- "${words[@]}")" -- "$cur"))
	__ltrim_colon_completions "$cur"
    # shellcheck disable=SC2181
    if [[ $? -ne 0 ]]; then
        unset COMPREPLY
    fi
    return 0
}

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    shopt -u hostcomplete && complete -o nospace -o bashdefault -o nosort -F _usage usage
else
    shopt -u hostcomplete && complete -o nospace -o bashdefault -F _usage usage
fi
# vim: noet ci pi sts=0 sw=4 ts=4 ft=sh
