#compdef rdl

autoload -U is-at-least

_rdl() {
    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[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
":: :_rdl_commands" \
"*::: :->rdl" \
&& ret=0
    case $state in
    (rdl)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:rdl-command-$line[1]:"
        case $line[1] in
            (render)
_arguments "${_arguments_options[@]}" \
'(-c --cloud)-u+[Render `locally`, in the `cloud` or in the given collective]:USING: ' \
'(-c --cloud)--using=[Render `locally`, in the `cloud` or in the given collective]:USING: ' \
'-t+[Launch the render using number of THREADS]:THREADS: ' \
'--threads=[Launch the render using number of THREADS]:THREADS: ' \
'-f+[FRAME(s) to render – 1,2,10-20,40-30@2]:FRAMES: ' \
'--frames=[FRAME(s) to render – 1,2,10-20,40-30@2]:FRAMES: ' \
'(-u --using)-c[Use 3Delight Cloud to render the specified file(s)]' \
'(-u --using)--cloud[Use 3Delight Cloud to render the specified file(s)]' \
'-d[Send the image(s) being rendered to 3Delight Display]' \
'--display[Send the image(s) being rendered to 3Delight Display]' \
'-v[Print the names of the file(s) being rendered]' \
'--verbose[Print the names of the file(s) being rendered]' \
'-p[Print rendering progress at each bucket]' \
'--progress[Print rendering progress at each bucket]' \
'--dry-run[Do not render, just print what would be done]' \
'-h[Print help information]' \
'--help[Print help information]' \
'*::FILE -- The NSI FILE(s) to render:' \
&& ret=0
;;
(cat)
_arguments "${_arguments_options[@]}" \
'-o+[Dump NSI stream to OUTPUT]:OUTPUT: ' \
'--output=[Dump NSI stream to OUTPUT]:OUTPUT: ' \
'-b[Encode NSI stream in binary format]' \
'--binary[Encode NSI stream in binary format]' \
'-g[Compress NSI stream using GNU zip format]' \
'--gzip[Compress NSI stream using GNU zip format]' \
'-e[Expand archives and procedurals]' \
'--expand[Expand archives and procedurals]' \
'--expand-archives[Expand archives]' \
'--expand-procedurals[Expand procedurals]' \
'-h[Print help information]' \
'--help[Print help information]' \
'::FILE -- The NSI FILE(s) to dump:' \
&& ret=0
;;
(generate-completions)
_arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
':shell -- The shell to generate completions for:(bash fish zsh powershell elvish)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" \
'*::subcommand -- The subcommand whose help message to display:' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_rdl_commands] )) ||
_rdl_commands() {
    local commands; commands=(
'render:Render an image of result with 3Delight' \
'cat:Dump the input as an NSI stream to stdout/a file' \
'generate-completions:Generate completion scripts for various shells' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'rdl commands' commands "$@"
}
(( $+functions[_rdl__cat_commands] )) ||
_rdl__cat_commands() {
    local commands; commands=()
    _describe -t commands 'rdl cat commands' commands "$@"
}
(( $+functions[_rdl__generate-completions_commands] )) ||
_rdl__generate-completions_commands() {
    local commands; commands=()
    _describe -t commands 'rdl generate-completions commands' commands "$@"
}
(( $+functions[_rdl__help_commands] )) ||
_rdl__help_commands() {
    local commands; commands=()
    _describe -t commands 'rdl help commands' commands "$@"
}
(( $+functions[_rdl__render_commands] )) ||
_rdl__render_commands() {
    local commands; commands=()
    _describe -t commands 'rdl render commands' commands "$@"
}

_rdl "$@"
