_teamtype() {
    local i cur prev opts cmd
    COMPREPLY=()
    if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
        cur="$2"
    else
        cur="${COMP_WORDS[COMP_CWORD]}"
    fi
    prev="$3"
    cmd=""
    opts=""

    for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="teamtype"
                ;;
            teamtype,client)
                cmd="teamtype__subcmd__client"
                ;;
            teamtype,help)
                cmd="teamtype__subcmd__help"
                ;;
            teamtype,join)
                cmd="teamtype__subcmd__join"
                ;;
            teamtype,share)
                cmd="teamtype__subcmd__share"
                ;;
            teamtype__subcmd__help,client)
                cmd="teamtype__subcmd__help__subcmd__client"
                ;;
            teamtype__subcmd__help,help)
                cmd="teamtype__subcmd__help__subcmd__help"
                ;;
            teamtype__subcmd__help,join)
                cmd="teamtype__subcmd__help__subcmd__join"
                ;;
            teamtype__subcmd__help,share)
                cmd="teamtype__subcmd__help__subcmd__share"
                ;;
            *)
                ;;
        esac
    done

    case "${cmd}" in
        teamtype)
            opts="-h -V --directory --help --version share join client help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --directory)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__client)
            opts="-h -V --directory --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --directory)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__help)
            opts="share join client help"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__help__subcmd__client)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__help__subcmd__help)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__help__subcmd__join)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__help__subcmd__share)
            opts=""
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__join)
            opts="-t -h -V --sync-vcs --magic-wormhole-relay --iroh-relay --iroh-dns-domain --iroh-pkarr-relay --username --temporary-directory --directory --help --version [JOIN_CODE]"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --magic-wormhole-relay)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --iroh-relay)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --iroh-dns-domain)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --iroh-pkarr-relay)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --username)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --directory)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        teamtype__subcmd__share)
            opts="-t -h -V --init --no-join-code --show-secret-address --sync-vcs --magic-wormhole-relay --iroh-relay --iroh-dns-domain --iroh-pkarr-relay --username --temporary-directory --directory --help --version"
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                --magic-wormhole-relay)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --iroh-relay)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --iroh-dns-domain)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --iroh-pkarr-relay)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --username)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                --directory)
                    COMPREPLY=($(compgen -f "${cur}"))
                    return 0
                    ;;
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
    esac
}

if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
    complete -F _teamtype -o nosort -o bashdefault -o default teamtype
else
    complete -F _teamtype -o bashdefault -o default teamtype
fi
