#compdef reaction

autoload -U is-at-least

_reaction() {
    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 (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
":: :_reaction_commands" \
"*::: :->reaction" \
&& ret=0
    case $state in
    (reaction)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:reaction-command-$line[1]:"
        case $line[1] in
            (start)
_arguments "${_arguments_options[@]}" : \
'-c+[configuration file in json, jsonnet or yaml format, or directory containing those files. required]:CONFIG:_files' \
'--config=[configuration file in json, jsonnet or yaml format, or directory containing those files. required]:CONFIG:_files' \
'-l+[minimum log level to show]:LOGLEVEL:_default' \
'--loglevel=[minimum log level to show]:LOGLEVEL:_default' \
'-s+[path to the client-daemon communication socket]:SOCKET:_files' \
'--socket=[path to the client-daemon communication socket]:SOCKET:_files' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" : \
'-s+[path to the client-daemon communication socket]:SOCKET:_files' \
'--socket=[path to the client-daemon communication socket]:SOCKET:_files' \
'-f+[how to format output]:FORMAT:(json yaml)' \
'--format=[how to format output]:FORMAT:(json yaml)' \
'-l+[only show items related to this STREAM\[.FILTER\]]:STREAM[.FILTER]:_default' \
'--limit=[only show items related to this STREAM\[.FILTER\]]:STREAM[.FILTER]:_default' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::patterns -- only show items matching name=PATTERN regex:_default' \
&& ret=0
;;
(flush)
_arguments "${_arguments_options[@]}" : \
'-s+[path to the client-daemon communication socket]:SOCKET:_files' \
'--socket=[path to the client-daemon communication socket]:SOCKET:_files' \
'-f+[how to format output]:FORMAT:(json yaml)' \
'--format=[how to format output]:FORMAT:(json yaml)' \
'-l+[only show items related to this STREAM\[.FILTER\]]:STREAM[.FILTER]:_default' \
'--limit=[only show items related to this STREAM\[.FILTER\]]:STREAM[.FILTER]:_default' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::patterns -- only show items matching name=PATTERN regex:_default' \
&& ret=0
;;
(trigger)
_arguments "${_arguments_options[@]}" : \
'-s+[path to the client-daemon communication socket]:SOCKET:_files' \
'--socket=[path to the client-daemon communication socket]:SOCKET:_files' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
':limit -- STREAM.FILTER to trigger:_default' \
'*::patterns -- PATTERNs to trigger on (e.g. ip=1.2.3.4):_default' \
&& ret=0
;;
(test-regex)
_arguments "${_arguments_options[@]}" : \
'-c+[configuration file in json, jsonnet or yaml format, or directory containing those files. required]:CONFIG:_files' \
'--config=[configuration file in json, jsonnet or yaml format, or directory containing those files. required]:CONFIG:_files' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
':regex -- Regex to test:_default' \
'::line -- Line to be tested:_default' \
&& ret=0
;;
(test-config)
_arguments "${_arguments_options[@]}" : \
'-c+[either a configuration file in json, jsonnet or yaml format, or a directory containing those files. required]:CONFIG:_files' \
'--config=[either a configuration file in json, jsonnet or yaml format, or a directory containing those files. required]:CONFIG:_files' \
'-f+[how to format output]:FORMAT:(json yaml)' \
'--format=[how to format output]:FORMAT:(json yaml)' \
'-v[whether to output additional information]' \
'--verbose[whether to output additional information]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_reaction__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:reaction-help-command-$line[1]:"
        case $line[1] in
            (start)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(flush)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(trigger)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(test-regex)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(test-config)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_reaction_commands] )) ||
_reaction_commands() {
    local commands; commands=(
'start:Start reaction daemon' \
'show:Show current matches and actions' \
'flush:Remove a target from reaction (e.g. unban)' \
'trigger:Trigger a target in reaction (e.g. ban)' \
'test-regex:Test a regex' \
'test-config:Test your configuration' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'reaction commands' commands "$@"
}
(( $+functions[_reaction__flush_commands] )) ||
_reaction__flush_commands() {
    local commands; commands=()
    _describe -t commands 'reaction flush commands' commands "$@"
}
(( $+functions[_reaction__help_commands] )) ||
_reaction__help_commands() {
    local commands; commands=(
'start:Start reaction daemon' \
'show:Show current matches and actions' \
'flush:Remove a target from reaction (e.g. unban)' \
'trigger:Trigger a target in reaction (e.g. ban)' \
'test-regex:Test a regex' \
'test-config:Test your configuration' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'reaction help commands' commands "$@"
}
(( $+functions[_reaction__help__flush_commands] )) ||
_reaction__help__flush_commands() {
    local commands; commands=()
    _describe -t commands 'reaction help flush commands' commands "$@"
}
(( $+functions[_reaction__help__help_commands] )) ||
_reaction__help__help_commands() {
    local commands; commands=()
    _describe -t commands 'reaction help help commands' commands "$@"
}
(( $+functions[_reaction__help__show_commands] )) ||
_reaction__help__show_commands() {
    local commands; commands=()
    _describe -t commands 'reaction help show commands' commands "$@"
}
(( $+functions[_reaction__help__start_commands] )) ||
_reaction__help__start_commands() {
    local commands; commands=()
    _describe -t commands 'reaction help start commands' commands "$@"
}
(( $+functions[_reaction__help__test-config_commands] )) ||
_reaction__help__test-config_commands() {
    local commands; commands=()
    _describe -t commands 'reaction help test-config commands' commands "$@"
}
(( $+functions[_reaction__help__test-regex_commands] )) ||
_reaction__help__test-regex_commands() {
    local commands; commands=()
    _describe -t commands 'reaction help test-regex commands' commands "$@"
}
(( $+functions[_reaction__help__trigger_commands] )) ||
_reaction__help__trigger_commands() {
    local commands; commands=()
    _describe -t commands 'reaction help trigger commands' commands "$@"
}
(( $+functions[_reaction__show_commands] )) ||
_reaction__show_commands() {
    local commands; commands=()
    _describe -t commands 'reaction show commands' commands "$@"
}
(( $+functions[_reaction__start_commands] )) ||
_reaction__start_commands() {
    local commands; commands=()
    _describe -t commands 'reaction start commands' commands "$@"
}
(( $+functions[_reaction__test-config_commands] )) ||
_reaction__test-config_commands() {
    local commands; commands=()
    _describe -t commands 'reaction test-config commands' commands "$@"
}
(( $+functions[_reaction__test-regex_commands] )) ||
_reaction__test-regex_commands() {
    local commands; commands=()
    _describe -t commands 'reaction test-regex commands' commands "$@"
}
(( $+functions[_reaction__trigger_commands] )) ||
_reaction__trigger_commands() {
    local commands; commands=()
    _describe -t commands 'reaction trigger commands' commands "$@"
}

if [ "$funcstack[1]" = "_reaction" ]; then
    _reaction "$@"
else
    compdef _reaction reaction
fi
