#compdef mado

autoload -U is-at-least

_mado() {
    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[@]}" : \
'--config=[A path to a TOML configuration file overriding a specific configuration option]:FILE:_files' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_mado_commands" \
"*::: :->mado" \
&& ret=0
    case $state in
    (mado)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:mado-command-$line[1]:"
        case $line[1] in
            (check)
_arguments "${_arguments_options[@]}" : \
'--output-format=[Output format for violations. The default format is "concise"]:OUTPUT_FORMAT:(concise mdl markdownlint)' \
'*--exclude=[List of file patterns to exclude from linting]:EXCLUDE:_default' \
'--quiet[Only log errors]' \
'-h[Print help]' \
'--help[Print help]' \
'*::files -- List of files or directories to check:_files' \
&& ret=0
;;
(generate-shell-completion)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell -- Shell to generate a completion script:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_mado__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_mado_commands] )) ||
_mado_commands() {
    local commands; commands=(
'check:Check markdown on the given files or directories' \
'generate-shell-completion:Generate shell completion' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'mado commands' commands "$@"
}
(( $+functions[_mado__check_commands] )) ||
_mado__check_commands() {
    local commands; commands=()
    _describe -t commands 'mado check commands' commands "$@"
}
(( $+functions[_mado__generate-shell-completion_commands] )) ||
_mado__generate-shell-completion_commands() {
    local commands; commands=()
    _describe -t commands 'mado generate-shell-completion commands' commands "$@"
}
(( $+functions[_mado__help_commands] )) ||
_mado__help_commands() {
    local commands; commands=(
'check:Check markdown on the given files or directories' \
'generate-shell-completion:Generate shell completion' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'mado help commands' commands "$@"
}
(( $+functions[_mado__help__check_commands] )) ||
_mado__help__check_commands() {
    local commands; commands=()
    _describe -t commands 'mado help check commands' commands "$@"
}
(( $+functions[_mado__help__generate-shell-completion_commands] )) ||
_mado__help__generate-shell-completion_commands() {
    local commands; commands=()
    _describe -t commands 'mado help generate-shell-completion commands' commands "$@"
}
(( $+functions[_mado__help__help_commands] )) ||
_mado__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'mado help help commands' commands "$@"
}

if [ "$funcstack[1]" = "_mado" ]; then
    _mado "$@"
else
    compdef _mado mado
fi
