#compdef hson

autoload -U is-at-least

_hson() {
    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+[]:BYTES:_default' \
'--bytes=[]:BYTES:_default' \
'-u+[Per-file Unicode character budget (adds up across files if no global chars limit)]:CHARS:_default' \
'--chars=[Per-file Unicode character budget (adds up across files if no global chars limit)]:CHARS:_default' \
'-n+[Per-file line budget. Pass --global-lines to also cap the total across inputs. Fileset headers/summary lines do not consume this budget.]:LINES:_default' \
'--lines=[Per-file line budget. Pass --global-lines to also cap the total across inputs. Fileset headers/summary lines do not consume this budget.]:LINES:_default' \
'--string-cap=[Maximum string length to display]:STRING_CAP:_default' \
'-C+[Total byte budget across all inputs. When combined with --bytes, the effective global limit is the smaller of the two.]:BYTES:_default' \
'--global-bytes=[Total byte budget across all inputs. When combined with --bytes, the effective global limit is the smaller of the two.]:BYTES:_default' \
'-N+[Total line budget across all inputs. Fileset headers/summary lines do not consume this budget.]:LINES:_default' \
'--global-lines=[Total line budget across all inputs. Fileset headers/summary lines do not consume this budget.]:LINES:_default' \
'-f+[Output format\: auto|json|yaml|text (filesets\: auto is per-file).]:FORMAT:(auto json yaml text)' \
'--format=[Output format\: auto|json|yaml|text (filesets\: auto is per-file).]:FORMAT:(auto json yaml text)' \
'-t+[Output style\: strict|default|detailed.]:STYLE:(strict default detailed)' \
'--template=[Output style\: strict|default|detailed.]:STYLE:(strict default detailed)' \
'--indent=[]:INDENT:_default' \
'*-g+[Additional input glob(s) to expand (respects .gitignore). Can be used multiple times.]::PATTERN:_default' \
'*--glob=[Additional input glob(s) to expand (respects .gitignore). Can be used multiple times.]::PATTERN:_default' \
'-i+[Input ingestion format\: json|yaml|text. Default is json for stdin/filesets; auto-detected for single-file auto runs.]:INPUT_FORMAT:(json jsonl yaml text)' \
'--input-format=[Input ingestion format\: json|yaml|text. Default is json for stdin/filesets; auto-detected for single-file auto runs.]:INPUT_FORMAT:(json jsonl yaml text)' \
'*--grep=[Guarantee inclusion of values (and their ancestors) matching this regex; budgets apply to everything else. Repeatable; multiple patterns match with OR.]:REGEX:_default' \
'*--igrep=[Case-insensitive --grep. Repeatable and combinable with --grep (OR).]:REGEX:_default' \
'*--weak-grep=[Bias priority toward matches without guaranteeing inclusion. Repeatable; multiple patterns match with OR. Can combine with --grep/--igrep.]:REGEX:_default' \
'*--weak-igrep=[Case-insensitive --weak-grep. Repeatable and combinable with --weak-grep (OR). Can combine with --grep/--igrep.]:REGEX:_default' \
'*--capped-grep=[Like --grep but respects the budget boundary (no forced inclusion).]:PATTERN:_default' \
'*--capped-igrep=[Like --igrep but respects the budget boundary (no forced inclusion).]:PATTERN:_default' \
'--grep-show=[When using --grep or --igrep, control fileset inclusion\: matching (default) | all]:GREP_SHOW:(matching all)' \
'--completions=[Print shell completions for the given shell]:SHELL:(bash elvish fish powershell zsh)' \
'-H[Count fileset headers/summary lines toward budgets instead of treating them as free]' \
'--count-headers[Count fileset headers/summary lines toward budgets instead of treating them as free]' \
'--no-space[]' \
'(-n --lines -N --global-lines)--no-newline[Do not add newlines in the output. Incompatible with --lines/--global-lines.]' \
'--no-header[Suppress fileset section headers in the output]' \
'(--no-header -m --compact --no-newline)--tree[Render filesets in a directory tree layout with inline previews]' \
'--no-sort[Keep input order for filesets (skip frecency/mtime sorting).]' \
'(--no-space --no-newline --indent)-m[Compact output with no added whitespace. Not very human-readable.]' \
'(--no-space --no-newline --indent)--compact[Compact output with no added whitespace. Not very human-readable.]' \
'--tail[Prefer the end of arrays when truncating. Strings unaffected; JSON stays strict.]' \
'(--tail)--head[Prefer the beginning of arrays when truncating (keep first N).]' \
'(--no-color)--color[Force enable ANSI colors in output]' \
'(--color)--no-color[Disable ANSI colors in output]' \
'(-g --glob)-r[Recursively expand directory inputs (like grep -r). Requires directory paths.]' \
'(-g --glob)--recursive[Recursively expand directory inputs (like grep -r). Requires directory paths.]' \
'--debug[Dump pruned internal tree (JSON) to stderr for the final render attempt]' \
'--count-matches[Print a summary of matched/hidden counts to stderr. Requires at least one grep flag.]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::inputs -- Optional file paths. If omitted, reads input from stdin. Multiple input files are supported. Directories are ignored unless --recursive is set; binary files are ignored with a warning on stderr.:_files' \
&& ret=0
}

(( $+functions[_hson_commands] )) ||
_hson_commands() {
    local commands; commands=()
    _describe -t commands 'hson commands' commands "$@"
}

if [ "$funcstack[1]" = "_hson" ]; then
    _hson "$@"
else
    compdef _hson hson
fi
