#compdef teamtype

autoload -U is-at-least

_teamtype() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'--directory=[The shared directory. Defaults to current directory]:DIRECTORY:_files' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_teamtype_commands" \
"*::: :->teamtype" \
&& ret=0
    case $state in
    (teamtype)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:teamtype-command-$line[1]:"
        case $line[1] in
            (share)
_arguments "${_arguments_options[@]}" : \
'--directory=[The shared directory. Defaults to current directory]:DIRECTORY:_files' \
'--init[Re-initialize the history of the shared directory. You will loose previous history]' \
'--no-join-code[Do not generate a join code. To prevent unintended sharing or simply if you want to keep Magic Wormhole out of the loop]' \
'--show-secret-address[Print the secret address. Useful for sharing with multiple people]' \
'--sync-vcs[EXPERIMENTAL\: Also synchronize version-control directories like .git/ or .jj/, which are normally ignored. For Git, this will synchronize all branches, commits, etc. as well as your .git/config. This means that new commits will immediately appear at all peers, you can change branches together, etc]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(join)
_arguments "${_arguments_options[@]}" : \
'--directory=[The shared directory. Defaults to current directory]:DIRECTORY:_files' \
'--sync-vcs[EXPERIMENTAL\: Also synchronize version-control directories like .git/ or .jj/, which are normally ignored. For Git, this will synchronize all branches, commits, etc. as well as your .git/config. This means that new commits will immediately appear at all peers, you can change branches together, etc]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::join_code -- Specify to connect to a new peer. Otherwise, try to connect to the most recent peer:_default' \
&& ret=0
;;
(client)
_arguments "${_arguments_options[@]}" : \
'--directory=[The shared directory. Defaults to current directory]:DIRECTORY:_files' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_teamtype__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:teamtype-help-command-$line[1]:"
        case $line[1] in
            (share)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(join)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(client)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_teamtype_commands] )) ||
_teamtype_commands() {
    local commands; commands=(
'share:Share a directory with a new peer' \
'join:Join a shared directory via a join code, or connect to the most recent one' \
'client:Open a JSON-RPC connection to the Teamtype daemon on stdin/stdout. Used by text editor plugins' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'teamtype commands' commands "$@"
}
(( $+functions[_teamtype__client_commands] )) ||
_teamtype__client_commands() {
    local commands; commands=()
    _describe -t commands 'teamtype client commands' commands "$@"
}
(( $+functions[_teamtype__help_commands] )) ||
_teamtype__help_commands() {
    local commands; commands=(
'share:Share a directory with a new peer' \
'join:Join a shared directory via a join code, or connect to the most recent one' \
'client:Open a JSON-RPC connection to the Teamtype daemon on stdin/stdout. Used by text editor plugins' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'teamtype help commands' commands "$@"
}
(( $+functions[_teamtype__help__client_commands] )) ||
_teamtype__help__client_commands() {
    local commands; commands=()
    _describe -t commands 'teamtype help client commands' commands "$@"
}
(( $+functions[_teamtype__help__help_commands] )) ||
_teamtype__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'teamtype help help commands' commands "$@"
}
(( $+functions[_teamtype__help__join_commands] )) ||
_teamtype__help__join_commands() {
    local commands; commands=()
    _describe -t commands 'teamtype help join commands' commands "$@"
}
(( $+functions[_teamtype__help__share_commands] )) ||
_teamtype__help__share_commands() {
    local commands; commands=()
    _describe -t commands 'teamtype help share commands' commands "$@"
}
(( $+functions[_teamtype__join_commands] )) ||
_teamtype__join_commands() {
    local commands; commands=()
    _describe -t commands 'teamtype join commands' commands "$@"
}
(( $+functions[_teamtype__share_commands] )) ||
_teamtype__share_commands() {
    local commands; commands=()
    _describe -t commands 'teamtype share commands' commands "$@"
}

if [ "$funcstack[1]" = "_teamtype" ]; then
    _teamtype "$@"
else
    compdef _teamtype teamtype
fi
