#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[@]}" : \
'-g+[Include or exclude files and directories for searching that match the given glob]:GLOB:_default' \
'--glob=[Include or exclude files and directories for searching that match the given glob]:GLOB:_default' \
'(--depth)-m+[Stop searching after NUM matches per input file]:NUM:_default' \
'(--depth)--max-count=[Stop searching after NUM matches per input file]:NUM:_default' \
'-f+[Input format (auto-detects from file extension if omitted)]:FORMAT:((auto\:"Detects from filetype, else defaults to JSON"
json\:"JSON format"
jsonl\:"JSONL format"
yaml\:"YAML format"
toml\:"TOML format"
cbor\:"CBOR format"
msgpack\:"\`MessagePack\` format"))' \
'--format=[Input format (auto-detects from file extension if omitted)]:FORMAT:((auto\:"Detects from filetype, else defaults to JSON"
json\:"JSON format"
jsonl\:"JSONL format"
yaml\:"YAML format"
toml\:"TOML format"
cbor\:"CBOR format"
msgpack\:"\`MessagePack\` format"))' \
'-o+[Output format (auto-detects from file extension if omitted)]:OUTPUT:((auto\:"Detects from filetype, else defaults to JSON"
json\:"JSON format"
jsonl\:"JSONL format"
yaml\:"YAML format"
toml\:"TOML format"
cbor\:"CBOR format"
msgpack\:"\`MessagePack\` format"))' \
'--output=[Output format (auto-detects from file extension if omitted)]:OUTPUT:((auto\:"Detects from filetype, else defaults to JSON"
json\:"JSON format"
jsonl\:"JSONL format"
yaml\:"YAML format"
toml\:"TOML format"
cbor\:"CBOR format"
msgpack\:"\`MessagePack\` format"))' \
'(--count --depth -n --no-display)--files[Prints the files that will be searched]' \
'(--count --depth -n --no-display)-l[Print only the names of files containing at least one match (like \`grep -l\`)]' \
'(--count --depth -n --no-display)--files-with-matches[Print only the names of files containing at least one match (like \`grep -l\`)]' \
'-i[Case insensitive search]' \
'--ignore-case[Case insensitive search]' \
'--compact[Do not pretty-print JSON output (ignored for non-JSON output formats)]' \
'-r[Print matched strings without JSON quotes or escaping (like \`jq -r\`)]' \
'--raw-output[Print matched strings without JSON quotes or escaping (like \`jq -r\`)]' \
'(--depth)--count[Display count of number of matches]' \
'(--count)--depth[Display depth of the input document]' \
'--porcelain[Machine-readable output\: strip labels and colors, print one JSON value per line (implies --compact)]' \
'-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]' \
'(--count --depth)-q[Quiet\: write nothing to stdout; communicate via the exit status only (errors still print to stderr)]' \
'(--count --depth)--quiet[Quiet\: write nothing to stdout; communicate via the exit status only (errors still print to stderr)]' \
'-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' \
'::inputs -- Optional path(s) to file(s). If omitted, reads from STDIN. With multiple files, the query is compiled once and run against each file, with a file heading before each file'\''s matches:_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__subcmd__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__subcmd__generate_commands] )) ||
_jg__subcmd__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__subcmd__generate__subcmd__man_commands] )) ||
_jg__subcmd__generate__subcmd__man_commands() {
    local commands; commands=()
    _describe -t commands 'jg generate man commands' commands "$@"
}
(( $+functions[_jg__subcmd__generate__subcmd__shell_commands] )) ||
_jg__subcmd__generate__subcmd__shell_commands() {
    local commands; commands=()
    _describe -t commands 'jg generate shell commands' commands "$@"
}

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