#compdef fblog

autoload -U is-at-least

_fblog() {
    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[@]}" : \
'(-x --excluded-value)*-a+[adds additional values]: :_default' \
'(-x --excluded-value)*--additional-value=[adds additional values]: :_default' \
'--config-file=[configuration file to load]: :_default' \
'--generate-completions=[]: :(bash elvish fish powershell zsh)' \
'*-m+[Adds an additional key to detect the message in the log entry. The first matching key will be assigned to \`fblog_message\`.]: :_default' \
'*--message-key=[Adds an additional key to detect the message in the log entry. The first matching key will be assigned to \`fblog_message\`.]: :_default' \
'*-t+[Adds an additional key to detect the time in the log entry. The first matching key will be assigned to \`fblog_timestamp\`.]: :_default' \
'*--time-key=[Adds an additional key to detect the time in the log entry. The first matching key will be assigned to \`fblog_timestamp\`.]: :_default' \
'*-l+[Adds an additional key to detect the level in the log entry. The first matching key will be assigned to \`fblog_level\`.]: :_default' \
'*--level-key=[Adds an additional key to detect the level in the log entry. The first matching key will be assigned to \`fblog_level\`.]: :_default' \
'*--map-level=[Rewrite the log level from one value to another.]:from=to:_default' \
'(-a --additional-value)*-x+[Excludes values (--dump-all is enabled implicitly)]: :_default' \
'(-a --additional-value)*--excluded-value=[Excludes values (--dump-all is enabled implicitly)]: :_default' \
'-f+[lua expression to filter log entries. \`message ~= nil and string.find(message, "text.*") ~= nil\`]: :_default' \
'--filter=[lua expression to filter log entries. \`message ~= nil and string.find(message, "text.*") ~= nil\`]: :_default' \
'--main-line-format=[Formats the main fblog output. All log values can be used. fblog provides sanitized variables starting with \`fblog_\`.]: :_default' \
'--additional-value-format=[Formats the additional value fblog output.]: :_default' \
'-c+[Use this key as the source of substitutions for the message. Value can either be an array ({1}) or an object ({key}).]: :_default' \
'--context-key=[Use this key as the source of substitutions for the message. Value can either be an array ({1}) or an object ({key}).]: :_default' \
'-F+[The format that should be used for substituting values in the message, where the key is the literal word \`key\`. Example\: \[\[key\]\] or \${key}.]: :_default' \
'--placeholder-format=[The format that should be used for substituting values in the message, where the key is the literal word \`key\`. Example\: \[\[key\]\] or \${key}.]: :_default' \
'--print-lua[Prints lua init expressions. Used for fblog debugging.]' \
'-d[dumps all values]' \
'--dump-all[dumps all values]' \
'-p[consider all text before opening curly brace as prefix]' \
'--with-prefix[consider all text before opening curly brace as prefix]' \
'--no-implicit-filter-return-statement[if you pass a filter expression '\''return'\'' is automatically prepended. Pass this switch to disable the implicit return.]' \
'-s[Enable substitution of placeholders in the log messages with their corresponding values from the context.]' \
'--substitute[Enable substitution of placeholders in the log messages with their corresponding values from the context.]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::INPUT -- Sets the input file to use, otherwise assumes stdin:_files' \
&& ret=0
}

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

if [ "$funcstack[1]" = "_fblog" ]; then
    _fblog "$@"
else
    compdef _fblog fblog
fi
