#compdef typstyle

autoload -U is-at-least

_typstyle() {
    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+[The column width of the output]:COLUMN: ' \
'--column=[The column width of the output]:COLUMN: ' \
'-a[Print the AST of the input file]' \
'--ast[Print the AST of the input file]' \
'-p[Print the pretty document]' \
'--pretty-doc[Print the pretty document]' \
'-i[Format the file in place]' \
'--inplace[Format the file in place]' \
'--check[Run in '\''check'\'' mode. Exits with 0 if input is formatted correctly. Exits with 1 if formatting is required]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::input -- Path to the input files, if not provided, read from stdin. If multiple files are provided, they will be processed in order:_files' \
":: :_typstyle_commands" \
"*::: :->typstyle" \
&& ret=0
    case $state in
    (typstyle)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:typstyle-command-$line[2]:"
        case $line[2] in
            (format-all)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'::directory -- The directory to format. If not provided, the current directory is used:_files' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell -- The shell to generate completions for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_typstyle__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:typstyle-help-command-$line[1]:"
        case $line[1] in
            (format-all)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_typstyle_commands] )) ||
_typstyle_commands() {
    local commands; commands=(
'format-all:Format all files in-place in the given directory' \
'completions:Generate shell completions for the given shell to stdout' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'typstyle commands' commands "$@"
}
(( $+functions[_typstyle__completions_commands] )) ||
_typstyle__completions_commands() {
    local commands; commands=()
    _describe -t commands 'typstyle completions commands' commands "$@"
}
(( $+functions[_typstyle__format-all_commands] )) ||
_typstyle__format-all_commands() {
    local commands; commands=()
    _describe -t commands 'typstyle format-all commands' commands "$@"
}
(( $+functions[_typstyle__help_commands] )) ||
_typstyle__help_commands() {
    local commands; commands=(
'format-all:Format all files in-place in the given directory' \
'completions:Generate shell completions for the given shell to stdout' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'typstyle help commands' commands "$@"
}
(( $+functions[_typstyle__help__completions_commands] )) ||
_typstyle__help__completions_commands() {
    local commands; commands=()
    _describe -t commands 'typstyle help completions commands' commands "$@"
}
(( $+functions[_typstyle__help__format-all_commands] )) ||
_typstyle__help__format-all_commands() {
    local commands; commands=()
    _describe -t commands 'typstyle help format-all commands' commands "$@"
}
(( $+functions[_typstyle__help__help_commands] )) ||
_typstyle__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'typstyle help help commands' commands "$@"
}

if [ "$funcstack[1]" = "_typstyle" ]; then
    _typstyle "$@"
else
    compdef _typstyle typstyle
fi
