#compdef zola

autoload -U is-at-least

_zola() {
    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[@]}" \
'-r+[Directory to use as root of project]:ROOT:_files' \
'--root=[Directory to use as root of project]:ROOT:_files' \
'-c+[Path to a config file other than config.toml in the root of project]:CONFIG:_files' \
'--config=[Path to a config file other than config.toml in the root of project]:CONFIG:_files' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_zola_commands" \
"*::: :->zola" \
&& ret=0
    case $state in
    (zola)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:zola-command-$line[1]:"
        case $line[1] in
            (init)
_arguments "${_arguments_options[@]}" \
'-f[Force creation of project even if directory is non-empty]' \
'--force[Force creation of project even if directory is non-empty]' \
'-h[Print help]' \
'--help[Print help]' \
'::name -- Name of the project. Will create a new directory with that name in the current directory:' \
&& ret=0
;;
(build)
_arguments "${_arguments_options[@]}" \
'-u+[Force the base URL to be that value (defaults to the one in config.toml)]:BASE_URL: ' \
'--base-url=[Force the base URL to be that value (defaults to the one in config.toml)]:BASE_URL: ' \
'-o+[Outputs the generated site in the given path (by default '\''public'\'' dir in project root)]:OUTPUT_DIR:_files' \
'--output-dir=[Outputs the generated site in the given path (by default '\''public'\'' dir in project root)]:OUTPUT_DIR:_files' \
'-f[Force building the site even if output directory is non-empty]' \
'--force[Force building the site even if output directory is non-empty]' \
'--drafts[Include drafts when loading the site]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(serve)
_arguments "${_arguments_options[@]}" \
'-i+[Interface to bind on]:INTERFACE: ' \
'--interface=[Interface to bind on]:INTERFACE: ' \
'-p+[Which port to use]:PORT: ' \
'--port=[Which port to use]:PORT: ' \
'-o+[Outputs assets of the generated site in the given path (by default '\''public'\'' dir in project root). HTML/XML will be stored in memory]:OUTPUT_DIR:_files' \
'--output-dir=[Outputs assets of the generated site in the given path (by default '\''public'\'' dir in project root). HTML/XML will be stored in memory]:OUTPUT_DIR:_files' \
'-u+[Changes the base_url]:BASE_URL: ' \
'--base-url=[Changes the base_url]:BASE_URL: ' \
'--force[Force use of the directory for serving the site even if output directory is non-empty]' \
'--drafts[Include drafts when loading the site]' \
'-O[Open site in the default browser]' \
'--open[Open site in the default browser]' \
'-f[Only rebuild the minimum on change - useful when working on a specific page/section]' \
'--fast[Only rebuild the minimum on change - useful when working on a specific page/section]' \
'--no-port-append[Default append port to the base url]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(check)
_arguments "${_arguments_options[@]}" \
'--drafts[Include drafts when loading the site]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(completion)
_arguments "${_arguments_options[@]}" \
'-h[Print help]' \
'--help[Print help]' \
':shell -- Shell to generate completion for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
":: :_zola__help_commands" \
"*::: :->help" \
&& ret=0

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

(( $+functions[_zola_commands] )) ||
_zola_commands() {
    local commands; commands=(
'init:Create a new Zola project' \
'build:Deletes the output directory if there is one and builds the site' \
'serve:Serve the site. Rebuild and reload on change automatically' \
'check:Try to build the project without rendering it. Checks links' \
'completion:Generate shell completion' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'zola commands' commands "$@"
}
(( $+functions[_zola__build_commands] )) ||
_zola__build_commands() {
    local commands; commands=()
    _describe -t commands 'zola build commands' commands "$@"
}
(( $+functions[_zola__help__build_commands] )) ||
_zola__help__build_commands() {
    local commands; commands=()
    _describe -t commands 'zola help build commands' commands "$@"
}
(( $+functions[_zola__check_commands] )) ||
_zola__check_commands() {
    local commands; commands=()
    _describe -t commands 'zola check commands' commands "$@"
}
(( $+functions[_zola__help__check_commands] )) ||
_zola__help__check_commands() {
    local commands; commands=()
    _describe -t commands 'zola help check commands' commands "$@"
}
(( $+functions[_zola__completion_commands] )) ||
_zola__completion_commands() {
    local commands; commands=()
    _describe -t commands 'zola completion commands' commands "$@"
}
(( $+functions[_zola__help__completion_commands] )) ||
_zola__help__completion_commands() {
    local commands; commands=()
    _describe -t commands 'zola help completion commands' commands "$@"
}
(( $+functions[_zola__help_commands] )) ||
_zola__help_commands() {
    local commands; commands=(
'init:Create a new Zola project' \
'build:Deletes the output directory if there is one and builds the site' \
'serve:Serve the site. Rebuild and reload on change automatically' \
'check:Try to build the project without rendering it. Checks links' \
'completion:Generate shell completion' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'zola help commands' commands "$@"
}
(( $+functions[_zola__help__help_commands] )) ||
_zola__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'zola help help commands' commands "$@"
}
(( $+functions[_zola__help__init_commands] )) ||
_zola__help__init_commands() {
    local commands; commands=()
    _describe -t commands 'zola help init commands' commands "$@"
}
(( $+functions[_zola__init_commands] )) ||
_zola__init_commands() {
    local commands; commands=()
    _describe -t commands 'zola init commands' commands "$@"
}
(( $+functions[_zola__help__serve_commands] )) ||
_zola__help__serve_commands() {
    local commands; commands=()
    _describe -t commands 'zola help serve commands' commands "$@"
}
(( $+functions[_zola__serve_commands] )) ||
_zola__serve_commands() {
    local commands; commands=()
    _describe -t commands 'zola serve commands' commands "$@"
}

if [ "$funcstack[1]" = "_zola" ]; then
    _zola "$@"
else
    compdef _zola zola
fi
