#compdef lighty-stats
## vim:ft=zsh
## completion for lighty-stats 0.2.2
## Daniel Friesel <derf@derf.homelinux.org>
## https://derf.homelinux.org/~derf/dotfiles/completion/_lighty-stats
## see also: https://derf.homelinux.org/~derf/code/lighty-stats

typeset -a arguments
typeset -A argument_pairs descriptions
typeset resolve arg

resolve='--resolve --no-resolve'

arguments=(
	'(--no-show-days)--show-days'
	'(--no-show-clients)--show-clients'
	'(--no-show-hosts)--show-hosts'
	'(--no-show-status)--show-status'
	'(--no-show-sites)--show-sites'
	'(--no-show-referers)--show-referers'
	'(--no-show-useragents)--show-useragents'
	'(--show-days)--no-show-days'
	'(--show-clients)--no-show-clients'
	'(--show-hosts)--no-show-hosts'
	'(--show-status)--no-show-status'
	'(--show-sites)--no-show-sites'
	'(--show-referers)--no-show-referers'
	'(--show-useragents)--no-show-usegarents'
	'(--no-resolve)--resolve'
	'(--resolve)--no-resolve'
	'*'{--format,-u}'[Output format]: :_format'
	'*'{--verbose,-v}'[Show progress information]'
	'*'{--file,-f}'=[Logfile to analyze]:file:_files'
	'--omission-chars=-[Omission chars]:omission chars'
	'--truncate-url=-[Trim paths]:integer:_guard "[0-9]#" "integer value"'
	'--truncate-referer=-[Trim referer paths]:integer:_guard "[0-9]#" "integer value"'
	'('$resolve')--truncate-client-ipv'{4,6}'=-[Trim client IPs]:integer:_guard "[0-9]#" "prefix length"'
	'*:file:_files'
)
argument_pairs=(
	'bytes'       'b'
	'config-file' 'F'
	'count'       'c'
	'custom-regex' 'C'
	'ignore'      'i'
	'log-format'  'l'
	'match'       'm'
	'use-formats' 'U'
	'width'       'w'
)
descriptions=(
	'bytes'        '[Count in bytes instead of hits]'
	'config-file'  '=-[Configuration file]:file:_files'
	'count'        '=[How many items to display]:integer:_guard "[0-9]#" "integer value"'
	'custom-regex' '=[custom parse regex]:regular expression'
	'ignore'       '=[Ignore lines matching this]:regex: '
	'log-format'   '=[logfile format]:format:(lighttpd vsftpd)'
	'match'        '=[Only show lines matching this]:regex: '
	'use-formats'  '=[Use formats]:when:(always auto never)'
	'width'        '=[Display width]:integer:_guard "[0-9]#" "integer value"'
)

for arg in ${(k)argument_pairs}; {
	arguments+='(--'$arg')-'${argument_pairs[$arg]}${descriptions[$arg]}
	arguments+='(-'${argument_pairs[$arg]}')--'${arg}${descriptions[$arg]}
}

function _format () {
	compset -q
	if compset -P '*=' || (( CURRENT > 1 )); then
		_wanted mode expl 'mode' \
		compadd -S ' ' -r \' -J mode clear reset bold dark underline underscore blink reverse concealed
		_wanted fgcolor expl 'foreground color' \
		compadd -S ' ' -r \' -J fgcolor black red green yellow blue magenta cyan white
		_wanted bgcolor expl 'background color' \
		compadd -S ' ' -r \' -J bgcolor on_black on_red on_green on_yellow on_blue on_magenta on_cyan on_white
	else
		_wanted format expl 'format' \
		compadd -S '=' title line_even line_uneven
	fi
}

_arguments -s $arguments
