#compdef jg

autoload -U is-at-least

_jg() {
    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[@]}" : \
'-f+[Input format (auto-detects from file extension if omitted)]:FORMAT:(auto json jsonl yaml toml cbor msgpack)' \
'--format=[Input format (auto-detects from file extension if omitted)]:FORMAT:(auto json jsonl yaml toml cbor msgpack)' \
'-i[Case insensitive search]' \
'--ignore-case[Case insensitive search]' \
'--compact[Do not pretty-print the JSON output]' \
'--count[Display count of number of matches]' \
'--depth[Display depth of the input document]' \
'-n[Do not display matched JSON values]' \
'--no-display[Do not display matched JSON values]' \
'-F[Treat the query as a literal field name and search at any depth]' \
'--fixed-string[Treat the query as a literal field name and search at any depth]' \
'(--no-path)--with-path[Always print the path header, even when output is piped]' \
'(--with-path)--no-path[Never print the path header, even in a terminal]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'::query -- Query string (e.g., "**.name"):_default' \
'::input -- Optional path to file. If omitted, reads from STDIN:_files' \
":: :_jg_commands" \
"*::: :->jg" \
&& ret=0
    case $state in
    (jg)
        words=($line[3] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:jg-command-$line[3]:"
        case $line[3] in
            (generate)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
":: :_jg__generate_commands" \
"*::: :->generate" \
&& ret=0

    case $state in
    (generate)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:jg-generate-command-$line[1]:"
        case $line[1] in
            (shell)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(man)
_arguments "${_arguments_options[@]}" : \
'-o+[The output directory to write the man pages]:OUTPUT_DIR:_files' \
'--output-dir=[The output directory to write the man pages]:OUTPUT_DIR:_files' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_jg_commands] )) ||
_jg_commands() {
    local commands; commands=(
'generate:Generate additional documentation and/or completions' \
    )
    _describe -t commands 'jg commands' commands "$@"
}
(( $+functions[_jg__generate_commands] )) ||
_jg__generate_commands() {
    local commands; commands=(
'shell:Generate shell completions for the given shell to stdout' \
'man:Generate a man page for jg to output directory if specified, else the current directory' \
    )
    _describe -t commands 'jg generate commands' commands "$@"
}
(( $+functions[_jg__generate__man_commands] )) ||
_jg__generate__man_commands() {
    local commands; commands=()
    _describe -t commands 'jg generate man commands' commands "$@"
}
(( $+functions[_jg__generate__shell_commands] )) ||
_jg__generate__shell_commands() {
    local commands; commands=()
    _describe -t commands 'jg generate shell commands' commands "$@"
}

if [ "$funcstack[1]" = "_jg" ]; then
    _jg "$@"
else
    compdef _jg jg
fi
