#compdef diffle

autoload -U is-at-least

_diffle() {
    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[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-p+[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'--port=[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'-H+[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--host=[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--allowed-origin=[trusted public HTTP(S) origin behind a reverse proxy (without a path)]:origin:_default' \
'--socket=[listen on a Unix socket at <path> that only you can connect to, in place of a port, e.g. to forward with ssh -L; opens no browser]:path:_files' \
'*--auto-viewed=[mark matching files viewed for this session (repeatable)]:glob:_default' \
'-U+[context lines around changes for this session (default\: config, 5)]:n:_default' \
'--context=[context lines around changes for this session (default\: config, 5)]:n:_default' \
'*--lsp=[language server command for one language, started for this run (repeatable); by default the diff'\''s languages are served by whatever is on PATH]:language=command:_default' \
'-v[print the version and exit]' \
'--version[print the version and exit]' \
'-h[display help for command]' \
'--help[display help for command]' \
'--no-open[do not open a browser]' \
'--keep-alive[keep the server running after all browser tabs close]' \
'--no-watch[do not watch for changes]' \
'--no-lsp[do not start any language server]' \
'--no-checkout[do not check out the new side of the review]' \
'--timing[print startup phase timings to stderr]' \
'::revs -- git-diff style revisions\: <rev> | <a>..<b> | <a>...<b> | <a> <b>:_default' \
":: :_diffle_commands" \
"*::: :->diffle" \
&& ret=0
    case $state in
    (diffle)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:diffle-command-$line[2]:"
        case $line[2] in
            (working)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-p+[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'--port=[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'-H+[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--host=[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--allowed-origin=[trusted public HTTP(S) origin behind a reverse proxy (without a path)]:origin:_default' \
'--socket=[listen on a Unix socket at <path> that only you can connect to, in place of a port, e.g. to forward with ssh -L; opens no browser]:path:_files' \
'*--auto-viewed=[mark matching files viewed for this session (repeatable)]:glob:_default' \
'-U+[context lines around changes for this session (default\: config, 5)]:n:_default' \
'--context=[context lines around changes for this session (default\: config, 5)]:n:_default' \
'*--lsp=[language server command for one language, started for this run (repeatable); by default the diff'\''s languages are served by whatever is on PATH]:language=command:_default' \
'--no-open[do not open a browser]' \
'--keep-alive[keep the server running after all browser tabs close]' \
'--no-watch[do not watch for changes]' \
'--no-lsp[do not start any language server]' \
'--no-checkout[do not check out the new side of the review]' \
'--timing[print startup phase timings to stderr]' \
'-h[display help for command]' \
'--help[display help for command]' \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-p+[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'--port=[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'-H+[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--host=[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--allowed-origin=[trusted public HTTP(S) origin behind a reverse proxy (without a path)]:origin:_default' \
'--socket=[listen on a Unix socket at <path> that only you can connect to, in place of a port, e.g. to forward with ssh -L; opens no browser]:path:_files' \
'*--auto-viewed=[mark matching files viewed for this session (repeatable)]:glob:_default' \
'-U+[context lines around changes for this session (default\: config, 5)]:n:_default' \
'--context=[context lines around changes for this session (default\: config, 5)]:n:_default' \
'*--lsp=[language server command for one language, started for this run (repeatable); by default the diff'\''s languages are served by whatever is on PATH]:language=command:_default' \
'--no-open[do not open a browser]' \
'--keep-alive[keep the server running after all browser tabs close]' \
'--no-watch[do not watch for changes]' \
'--no-lsp[do not start any language server]' \
'--no-checkout[do not check out the new side of the review]' \
'--timing[print startup phase timings to stderr]' \
'-h[display help for command]' \
'--help[display help for command]' \
'::rev -- the commit to review:_default' \
&& ret=0
;;
(pr)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-p+[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'--port=[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'-H+[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--host=[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--allowed-origin=[trusted public HTTP(S) origin behind a reverse proxy (without a path)]:origin:_default' \
'--socket=[listen on a Unix socket at <path> that only you can connect to, in place of a port, e.g. to forward with ssh -L; opens no browser]:path:_files' \
'*--auto-viewed=[mark matching files viewed for this session (repeatable)]:glob:_default' \
'-U+[context lines around changes for this session (default\: config, 5)]:n:_default' \
'--context=[context lines around changes for this session (default\: config, 5)]:n:_default' \
'*--lsp=[language server command for one language, started for this run (repeatable); by default the diff'\''s languages are served by whatever is on PATH]:language=command:_default' \
'--no-open[do not open a browser]' \
'--keep-alive[keep the server running after all browser tabs close]' \
'--no-watch[do not watch for changes]' \
'--no-lsp[do not start any language server]' \
'--no-checkout[do not check out the new side of the review]' \
'--timing[print startup phase timings to stderr]' \
'-h[display help for command]' \
'--help[display help for command]' \
'::pr -- pull request number or url; default\: the pull request for this branch:_default' \
&& ret=0
;;
(range-diff)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-p+[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'--port=[port to listen on (default\: 4966, or the next free one; 0 = random)]:port:_default' \
'-H+[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--host=[address to bind; use 0.0.0.0 to expose on the network (default\: 127.0.0.1)]:host:_default' \
'--allowed-origin=[trusted public HTTP(S) origin behind a reverse proxy (without a path)]:origin:_default' \
'--socket=[listen on a Unix socket at <path> that only you can connect to, in place of a port, e.g. to forward with ssh -L; opens no browser]:path:_files' \
'*--auto-viewed=[mark matching files viewed for this session (repeatable)]:glob:_default' \
'-U+[context lines around changes for this session (default\: config, 5)]:n:_default' \
'--context=[context lines around changes for this session (default\: config, 5)]:n:_default' \
'*--lsp=[language server command for one language, started for this run (repeatable); by default the diff'\''s languages are served by whatever is on PATH]:language=command:_default' \
'--no-open[do not open a browser]' \
'--keep-alive[keep the server running after all browser tabs close]' \
'--no-watch[do not watch for changes]' \
'--no-lsp[do not start any language server]' \
'--no-checkout[do not check out the new side of the review]' \
'--timing[print startup phase timings to stderr]' \
'-h[display help for command]' \
'--help[display help for command]' \
'*::ranges -- two ranges\: <a>..<b> <c>..<d>, <base> <b> <d>, or <b>...<d>:_default' \
&& ret=0
;;
(comments)
_arguments "${_arguments_options[@]}" : \
'-h[display help for command]' \
'--help[display help for command]' \
":: :_diffle__subcmd__comments_commands" \
"*::: :->comments" \
&& ret=0

    case $state in
    (comments)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:diffle-comments-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
'--state=[which threads to print (default\: all)]:state:(open resolved all)' \
'--path=[only the threads on this file, relative to the repository root]:path:_default' \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-h[display help for command]' \
'--help[display help for command]' \
&& ret=0
;;
(reply)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-h[display help for command]' \
'--help[display help for command]' \
':thread -- the thread'\''s id, as `diffle comments list` prints it:_default' \
':body -- the reply, in Markdown (`-`\: stdin):_default' \
&& ret=0
;;
        esac
    ;;
esac
;;
(tour)
_arguments "${_arguments_options[@]}" : \
'-h[display help for command]' \
'--help[display help for command]' \
":: :_diffle__subcmd__tour_commands" \
"*::: :->tour" \
&& ret=0

    case $state in
    (tour)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:diffle-tour-command-$line[1]:"
        case $line[1] in
            (push)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-h[display help for command]' \
'--help[display help for command]' \
'::file -- the HTML document (default\: stdin):_files' \
&& ret=0
;;
(clear)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-h[display help for command]' \
'--help[display help for command]' \
&& ret=0
;;
(export)
_arguments "${_arguments_options[@]}" : \
'-C+[run as if started in <path> (any directory inside a git worktree)]:path:_files -/' \
'-h[display help for command]' \
'--help[display help for command]' \
':file -- where to write the file (`-`\: stdout):_files' \
&& ret=0
;;
        esac
    ;;
esac
;;
(skill)
_arguments "${_arguments_options[@]}" : \
'--no-frontmatter[leave out the frontmatter that names the skill and says when to use it]' \
'-h[display help for command]' \
'--help[display help for command]' \
&& ret=0
;;
(config)
_arguments "${_arguments_options[@]}" : \
'-h[display help for command]' \
'--help[display help for command]' \
&& ret=0
;;
(lsp)
_arguments "${_arguments_options[@]}" : \
'-h[display help for command]' \
'--help[display help for command]' \
&& ret=0
;;
(completion)
_arguments "${_arguments_options[@]}" : \
'-s+[shell to generate the script for]:shell:(bash elvish fish powershell zsh)' \
'--shell=[shell to generate the script for]:shell:(bash elvish fish powershell zsh)' \
'-h[display help for command]' \
'--help[display help for command]' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_diffle_commands] )) ||
_diffle_commands() {
    local commands; commands=(
'working:Same as \`diffle HEAD..worktree\`\: uncommitted changes, staged and untracked files included.' \
'show:Same as \`diffle <rev>^!\`\: one commit against its first parent, as git show shows it.' \
'pr:A GitHub pull request, as GitHub shows it\: merge-base(base, head) vs head.' \
'range-diff:How one series of commits became another, as git range-diff shows it\: the older range replayed onto the newer one’s base against the newer range, with the commits paired.' \
'comments:read and answer the comments of the review running for this repository, as an agent' \
'tour:show a guided tour of the review diffle is running for this repository, as an agent' \
'skill:print what diffle offers a coding agent, as a skill to install as is' \
'config:print the config file path and contents' \
'lsp:show the language server each language would get, and what is missing from PATH' \
'completion:print a shell completion script' \
    )
    _describe -t commands 'diffle commands' commands "$@"
}
(( $+functions[_diffle__subcmd__comments_commands] )) ||
_diffle__subcmd__comments_commands() {
    local commands; commands=(
'list:print the threads the reviewer is shown, with the key of their set, as JSON' \
'reply:reply to a thread as the agent; prints the thread as JSON' \
    )
    _describe -t commands 'diffle comments commands' commands "$@"
}
(( $+functions[_diffle__subcmd__comments__subcmd__list_commands] )) ||
_diffle__subcmd__comments__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'diffle comments list commands' commands "$@"
}
(( $+functions[_diffle__subcmd__comments__subcmd__reply_commands] )) ||
_diffle__subcmd__comments__subcmd__reply_commands() {
    local commands; commands=()
    _describe -t commands 'diffle comments reply commands' commands "$@"
}
(( $+functions[_diffle__subcmd__completion_commands] )) ||
_diffle__subcmd__completion_commands() {
    local commands; commands=()
    _describe -t commands 'diffle completion commands' commands "$@"
}
(( $+functions[_diffle__subcmd__config_commands] )) ||
_diffle__subcmd__config_commands() {
    local commands; commands=()
    _describe -t commands 'diffle config commands' commands "$@"
}
(( $+functions[_diffle__subcmd__lsp_commands] )) ||
_diffle__subcmd__lsp_commands() {
    local commands; commands=()
    _describe -t commands 'diffle lsp commands' commands "$@"
}
(( $+functions[_diffle__subcmd__pr_commands] )) ||
_diffle__subcmd__pr_commands() {
    local commands; commands=()
    _describe -t commands 'diffle pr commands' commands "$@"
}
(( $+functions[_diffle__subcmd__range-diff_commands] )) ||
_diffle__subcmd__range-diff_commands() {
    local commands; commands=()
    _describe -t commands 'diffle range-diff commands' commands "$@"
}
(( $+functions[_diffle__subcmd__show_commands] )) ||
_diffle__subcmd__show_commands() {
    local commands; commands=()
    _describe -t commands 'diffle show commands' commands "$@"
}
(( $+functions[_diffle__subcmd__skill_commands] )) ||
_diffle__subcmd__skill_commands() {
    local commands; commands=()
    _describe -t commands 'diffle skill commands' commands "$@"
}
(( $+functions[_diffle__subcmd__tour_commands] )) ||
_diffle__subcmd__tour_commands() {
    local commands; commands=(
'push:check an HTML tour and show it in place of the review'\''s tour; prints it as JSON' \
'clear:remove the review'\''s tour' \
'export:save the review'\''s tour as one HTML file that reads offline, as the tour view'\''s Export does; an open diffle tab bakes it' \
    )
    _describe -t commands 'diffle tour commands' commands "$@"
}
(( $+functions[_diffle__subcmd__tour__subcmd__clear_commands] )) ||
_diffle__subcmd__tour__subcmd__clear_commands() {
    local commands; commands=()
    _describe -t commands 'diffle tour clear commands' commands "$@"
}
(( $+functions[_diffle__subcmd__tour__subcmd__export_commands] )) ||
_diffle__subcmd__tour__subcmd__export_commands() {
    local commands; commands=()
    _describe -t commands 'diffle tour export commands' commands "$@"
}
(( $+functions[_diffle__subcmd__tour__subcmd__push_commands] )) ||
_diffle__subcmd__tour__subcmd__push_commands() {
    local commands; commands=()
    _describe -t commands 'diffle tour push commands' commands "$@"
}
(( $+functions[_diffle__subcmd__working_commands] )) ||
_diffle__subcmd__working_commands() {
    local commands; commands=()
    _describe -t commands 'diffle working commands' commands "$@"
}

if [ "$funcstack[1]" = "_diffle" ]; then
    _diffle "$@"
else
    compdef _diffle diffle
fi
