#compdef rage

autoload -U is-at-least

_rage() {
    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[@]}" : \
'--max-work-factor=[Maximum work factor to allow for passphrase decryption.]:WF:_default' \
'*-r+[Encrypt to the specified RECIPIENT. May be repeated.]:RECIPIENT:_default' \
'*--recipient=[Encrypt to the specified RECIPIENT. May be repeated.]:RECIPIENT:_default' \
'*-R+[Encrypt to the recipients listed at PATH. May be repeated.]:PATH:_files' \
'*--recipients-file=[Encrypt to the recipients listed at PATH. May be repeated.]:PATH:_files' \
'*-i+[Use the identity file at IDENTITY. May be repeated.]:IDENTITY:_files' \
'*--identity=[Use the identity file at IDENTITY. May be repeated.]:IDENTITY:_files' \
'-j+[Use age-plugin-PLUGIN-NAME in its default mode as an identity.]:PLUGIN-NAME:_default' \
'-o+[Write the result to the file at path OUTPUT.]:OUTPUT:_files' \
'--output=[Write the result to the file at path OUTPUT.]:OUTPUT:_files' \
'-h[Print this help message and exit.]' \
'--help[Print this help message and exit.]' \
'-V[Print version info and exit.]' \
'--version[Print version info and exit.]' \
'-e[Encrypt the input (the default).]' \
'--encrypt[Encrypt the input (the default).]' \
'-d[Decrypt the input.]' \
'--decrypt[Decrypt the input.]' \
'-p[Encrypt with a passphrase instead of recipients.]' \
'--passphrase[Encrypt with a passphrase instead of recipients.]' \
'-a[Encrypt to a PEM encoded format.]' \
'--armor[Encrypt to a PEM encoded format.]' \
'::input -- Path to a file to read from.:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_rage" ]; then
    _rage "$@"
else
    compdef _rage rage
fi
