#compdef dochelp _dochelp-cat() { _arguments \ ':docid Document ID to print:_files' } _dochelp-info() { _arguments \ ':docid Document ID to print:_files' } _dochelp-search() { _arguments \ ':optional regexp:_files' } _dochelp-update() { _arguments \ '::optional target:_files' \ '--online[Use relative paths in generated HTML page]' } _dochelp() { local curcontext="$curcontext" state line typeset -A opt_args _arguments -C \ ':command:->command' \ '*::options:->options' \ case $state in (command) #breaks if defined outside the func local -a subcommands subcommands=( 'cat:Dump the content of a document' 'info:Print available information about a document' 'list:List known registered documents' 'search:Look for matching documents' 'update:Print available information for a document' ) _describe -t commands dochelp subcommands ;; (options) _arguments \ '--help[print a help message]' \ '--version[print version number]' \ '--base-doc[Specify doc-base directory]:directory:_path_files -/' local funcname funcname=_dochelp-$line[1] if type $funcname | grep -q "shell function" ; then $funcname fi ;; esac } _dochelp "$@"