#compdef sile

autoload -U is-at-least

_sile() {
    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[@]}" : \
'-b+[Specify the output backend]:BACKEND:_default' \
'--backend=[Specify the output backend]:BACKEND:_default' \
'-c+[Override the default or specified document class]:CLASS:_default' \
'--class=[Override the default or specified document class]:CLASS:_default' \
'*-d+[Show debug information for tagged aspects of SILE’s operation]:DEBUGFLAG[,DEBUGFLAG]:_default' \
'*--debug=[Show debug information for tagged aspects of SILE’s operation]:DEBUGFLAG[,DEBUGFLAG]:_default' \
'*-e+[Evaluate Lua expression before processing input]:EXRPESION:_default' \
'*--evaluate=[Evaluate Lua expression before processing input]:EXRPESION:_default' \
'*-E+[Evaluate Lua expression after processing input]:EXRPESION:_default' \
'*--evaluate-after=[Evaluate Lua expression after processing input]:EXRPESION:_default' \
'-f+[Specify which font manager to use]:FONTMANAGER:_default' \
'--fontmanager=[Specify which font manager to use]:FONTMANAGER:_default' \
'-m+[Generate a Makefile format list of dependencies and white them to a file]:FILE:_files' \
'--makedeps=[Generate a Makefile format list of dependencies and white them to a file]:FILE:_files' \
'-o+[Explicitly set the output file name]:FILE:_files' \
'--output=[Explicitly set the output file name]:FILE:_files' \
'*-O+[Set or override document class options]:OPTION:_default' \
'*--option=[Set or override document class options]:OPTION:_default' \
'*-p+[Include the contents of a SIL, XML, or other resource file before the input document content]:FILE:_files' \
'*--preamble=[Include the contents of a SIL, XML, or other resource file before the input document content]:FILE:_files' \
'*-P+[Include the contents of a SIL, XML, or other resource file after the input document content]:FILE:_files' \
'*--postamble=[Include the contents of a SIL, XML, or other resource file after the input document content]:FILE:_files' \
'*-u+[Load and initialize a class, inputter, shaper, or other module before processing the main input]:MODULE[[PARAMETER=VALUE[,PARAMETER=VALUE]]]:_default' \
'*--use=[Load and initialize a class, inputter, shaper, or other module before processing the main input]:MODULE[[PARAMETER=VALUE[,PARAMETER=VALUE]]]:_default' \
'-q[Suppress warnings and informational messages during processing]' \
'--quiet[Suppress warnings and informational messages during processing]' \
'-t[Display detailed location trace on errors and warnings]' \
'--traceback[Display detailed location trace on errors and warnings]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::input -- Input document filename(s), by default in SIL, XML, or Lua formats:_files' \
&& ret=0
}

(( $+functions[_sile_commands] )) ||
_sile_commands() {
    local commands; commands=()
    _describe -t commands 'sile commands' commands "$@"
}

if [ "$funcstack[1]" = "_sile" ]; then
    _sile "$@"
else
    compdef _sile sile
fi
