#compdef kdlfmt

autoload -U is-at-least

_kdlfmt() {
    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[@]}" : \
'--log-level=[]:LOG_LEVEL:(trace debug info warn error off)' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_kdlfmt_commands" \
"*::: :->kdlfmt" \
&& ret=0
    case $state in
    (kdlfmt)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:kdlfmt-command-$line[1]:"
        case $line[1] in
            (format)
_arguments "${_arguments_options[@]}" : \
'--kdl-version=[kdl specification to use]:KDL_VERSION:(v1 v2)' \
'--config=[Path to config file]:CONFIG:_files' \
'--log-level=[]:LOG_LEVEL:(trace debug info warn error off)' \
'--stdin[Read from stdin and print to stdout]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'*::input -- Path to file OR directory:_default' \
&& ret=0
;;
(check)
_arguments "${_arguments_options[@]}" : \
'--kdl-version=[kdl specification to use]:KDL_VERSION:(v1 v2)' \
'--config=[Path to config file]:CONFIG:_files' \
'--log-level=[]:LOG_LEVEL:(trace debug info warn error off)' \
'--stdin[Read from stdin and print to stdout]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
'*::input -- Path to file OR directory:_default' \
&& ret=0
;;
(init)
_arguments "${_arguments_options[@]}" : \
'--kdl-version=[kdl specification to use]:KDL_VERSION:(v1 v2)' \
'--log-level=[]:LOG_LEVEL:(trace debug info warn error off)' \
'--force[Create config even if one already exists in current directory]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'--log-level=[]:LOG_LEVEL:(trace debug info warn error off)' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':shell:(bash elvish fish nushell powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_kdlfmt__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_kdlfmt_commands] )) ||
_kdlfmt_commands() {
    local commands; commands=(
'format:Format kdl files' \
'check:Validate files are formatted' \
'init:Initialize formatter config' \
'completions:Generate shell completions' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kdlfmt commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__check_commands] )) ||
_kdlfmt__subcmd__check_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt check commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__completions_commands] )) ||
_kdlfmt__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt completions commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__format_commands] )) ||
_kdlfmt__subcmd__format_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt format commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__help_commands] )) ||
_kdlfmt__subcmd__help_commands() {
    local commands; commands=(
'format:Format kdl files' \
'check:Validate files are formatted' \
'init:Initialize formatter config' \
'completions:Generate shell completions' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'kdlfmt help commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__help__subcmd__check_commands] )) ||
_kdlfmt__subcmd__help__subcmd__check_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt help check commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__help__subcmd__completions_commands] )) ||
_kdlfmt__subcmd__help__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt help completions commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__help__subcmd__format_commands] )) ||
_kdlfmt__subcmd__help__subcmd__format_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt help format commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__help__subcmd__help_commands] )) ||
_kdlfmt__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt help help commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__help__subcmd__init_commands] )) ||
_kdlfmt__subcmd__help__subcmd__init_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt help init commands' commands "$@"
}
(( $+functions[_kdlfmt__subcmd__init_commands] )) ||
_kdlfmt__subcmd__init_commands() {
    local commands; commands=()
    _describe -t commands 'kdlfmt init commands' commands "$@"
}

if [ "$funcstack[1]" = "_kdlfmt" ]; then
    _kdlfmt "$@"
else
    compdef _kdlfmt kdlfmt
fi
