#compdef tombi

autoload -U is-at-least

_tombi() {
    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[@]}" : \
'*-v[Change the logging level]' \
'*--verbose[Change the logging level]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_tombi_commands" \
"*::: :->tombi" \
&& ret=0
    case $state in
    (tombi)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:tombi-command-$line[1]:"
        case $line[1] in
            (format)
_arguments "${_arguments_options[@]}" : \
'--stdin-filename=[Filename to use when reading from stdin]:STDIN_FILENAME:_default' \
'--check[Check only and don'\''t overwrite files]' \
'--diff[Show format changes]' \
'--quiet[Quiet mode]' \
'--offline[Disable network access]' \
'--no-cache[Do not use cache]' \
'*-v[Change the logging level]' \
'*--verbose[Change the logging level]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::files -- List of files or directories to format:_default' \
&& ret=0
;;
(lint)
_arguments "${_arguments_options[@]}" : \
'--stdin-filename=[Filename to use when reading from stdin]:STDIN_FILENAME:_default' \
'--error-on-warnings[Exit with error code on warnings]' \
'--quiet[Quiet mode]' \
'--offline[Disable network access]' \
'--no-cache[Do not use cache]' \
'*-v[Change the logging level]' \
'*--verbose[Change the logging level]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::files -- List of files or directories to lint:_default' \
&& ret=0
;;
(lsp)
_arguments "${_arguments_options[@]}" : \
'--offline[Disable network access]' \
'--no-cache[Do not use cache]' \
'*-v[Change the logging level]' \
'*--verbose[Change the logging level]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(completion)
_arguments "${_arguments_options[@]}" : \
'*-v[Change the logging level]' \
'*--verbose[Change the logging level]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
':shell -- Shell to generate completion for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_tombi_commands] )) ||
_tombi_commands() {
    local commands; commands=(
'format:Format TOML files' \
'lint:Lint TOML files' \
'lsp:Run TOML Language Server' \
'completion:Generate shell completion' \
    )
    _describe -t commands 'tombi commands' commands "$@"
}
(( $+functions[_tombi__completion_commands] )) ||
_tombi__completion_commands() {
    local commands; commands=()
    _describe -t commands 'tombi completion commands' commands "$@"
}
(( $+functions[_tombi__format_commands] )) ||
_tombi__format_commands() {
    local commands; commands=()
    _describe -t commands 'tombi format commands' commands "$@"
}
(( $+functions[_tombi__lint_commands] )) ||
_tombi__lint_commands() {
    local commands; commands=()
    _describe -t commands 'tombi lint commands' commands "$@"
}
(( $+functions[_tombi__lsp_commands] )) ||
_tombi__lsp_commands() {
    local commands; commands=()
    _describe -t commands 'tombi lsp commands' commands "$@"
}

if [ "$funcstack[1]" = "_tombi" ]; then
    _tombi "$@"
else
    compdef _tombi tombi
fi
