#compdef casile

autoload -U is-at-least

_casile() {
    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[@]}" : \
'-l+[Set language]:LANGUAGE:_default' \
'--language=[Set language]:LANGUAGE:_default' \
'-P+[Set project root path]:PROJECT:_files -/' \
'--project=[Set project root path]:PROJECT:_files -/' \
'-d[Enable extra debug output from tooling]' \
'--debug[Enable extra debug output from tooling]' \
'-p[Eschew all UI output and just pass the subprocess output through]' \
'--passthrough[Eschew all UI output and just pass the subprocess output through]' \
'-q[Discard all non-error output messages]' \
'--quiet[Discard all non-error output messages]' \
'-v[Enable extra verbose output from tooling]' \
'--verbose[Enable extra verbose output from tooling]' \
'-h[Print help]' \
'--help[Print help]' \
":: :_casile_commands" \
"*::: :->casile" \
&& ret=0
    case $state in
    (casile)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:casile-command-$line[1]:"
        case $line[1] in
            (make)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
'*::target -- Target(s) as defined by CaSILE in project rules:_files' \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':name -- Run script name as supplied by CaSILE, toolkit, or project:_command_names -e' \
'*::arguments -- Arguments to pass to script being run:_default' \
&& ret=0
;;
(setup)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_casile__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:casile-help-command-$line[1]:"
        case $line[1] in
            (make)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(run)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(setup)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(status)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_casile_commands] )) ||
_casile_commands() {
    local commands; commands=(
'make:Build specified target(s) with ‘make’' \
'run:Run helper script inside CaSILE environment' \
'setup:Configure a publishing project repository' \
'status:Show status information about setup, configuration, and build state' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'casile commands' commands "$@"
}
(( $+functions[_casile__help_commands] )) ||
_casile__help_commands() {
    local commands; commands=(
'make:Build specified target(s) with ‘make’' \
'run:Run helper script inside CaSILE environment' \
'setup:Configure a publishing project repository' \
'status:Show status information about setup, configuration, and build state' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'casile help commands' commands "$@"
}
(( $+functions[_casile__help__help_commands] )) ||
_casile__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'casile help help commands' commands "$@"
}
(( $+functions[_casile__help__make_commands] )) ||
_casile__help__make_commands() {
    local commands; commands=()
    _describe -t commands 'casile help make commands' commands "$@"
}
(( $+functions[_casile__help__run_commands] )) ||
_casile__help__run_commands() {
    local commands; commands=()
    _describe -t commands 'casile help run commands' commands "$@"
}
(( $+functions[_casile__help__setup_commands] )) ||
_casile__help__setup_commands() {
    local commands; commands=()
    _describe -t commands 'casile help setup commands' commands "$@"
}
(( $+functions[_casile__help__status_commands] )) ||
_casile__help__status_commands() {
    local commands; commands=()
    _describe -t commands 'casile help status commands' commands "$@"
}
(( $+functions[_casile__make_commands] )) ||
_casile__make_commands() {
    local commands; commands=()
    _describe -t commands 'casile make commands' commands "$@"
}
(( $+functions[_casile__run_commands] )) ||
_casile__run_commands() {
    local commands; commands=()
    _describe -t commands 'casile run commands' commands "$@"
}
(( $+functions[_casile__setup_commands] )) ||
_casile__setup_commands() {
    local commands; commands=()
    _describe -t commands 'casile setup commands' commands "$@"
}
(( $+functions[_casile__status_commands] )) ||
_casile__status_commands() {
    local commands; commands=()
    _describe -t commands 'casile status commands' commands "$@"
}

if [ "$funcstack[1]" = "_casile" ]; then
    _casile "$@"
else
    compdef _casile casile
fi
