#compdef khard

# Zsh completion definition for khard
# Install by copying to a directory where zsh searches for completion
# functions (the $fpath array).
#
# If you, for example, put all completion functions into the folder ~/.zsh/completions you must add
# the following to your zsh main config file ~/.zshrc:
#   fpath=( $HOME/.zsh/completions $fpath )
#   autoload -U compinit
#   compinit
#
# More information at http://is.muni.cz/www/xsiska2/2014/08/05/generating-completing-functions.html

local curcontext="$curcontext"
local -a state line expl
local -A opt_args

_arguments -s \
    {-a+,--addressbook=}'[specify addressbook]:addressbook:->addressbooks' \
    {-g,--group-by-addressbook}'[Group contact table by address book]' \
    '--open-editor[Open text editor after successful creation of new contact from stdin or template]' \
    {-r,--reverse}'[Reverse order of contact table]' \
    {-s+,--search=}'[search for contacts]:search string' \
    '--sort=[sort contact table]:order:(first_name last_name)' \
    {-t+,--template-file=}'[Specify template file to create, modify or export contacts]:template file:_files' \
    {-u+,--uid=}'[Select contact by uid]:uid' \
    '(- 1)'{-h,--help}'[show help information]' \
    '(- 1)'{-v,--version}'[show version information]' \
    '1:action:(list details export email phone source new add-email merge modify copy move remove)' && return

if [[ -n $state ]]; then
    _sequence _wanted addressbooks expl "addressbook" compadd - \
        ${${=${"$(_call_program addressbooks ${words[1]} -a , 2>&1)"}##*:}//,/}
fi
