Do not use state mechanism

Call a dispatch function instead, simplifying the nested select case.
This commit is contained in:
Aljaž "g5pw" Srebrnič 2013-03-31 23:29:55 +02:00
parent 54ed122d25
commit 3e6040e01d
1 changed files with 46 additions and 48 deletions

View File

@ -73,56 +73,54 @@ _port() {
'-y[Perform a dry run.]' \ '-y[Perform a dry run.]' \
'-t[enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ '-t[enable trace mode debug facilities on platforms that support it (Mac OS X).]' \
"1:Port actions:($actions)" \ "1:Port actions:($actions)" \
'*:extra:->extra' \ '*:extra:_port_dispatch' \
&& return 0 && return 0
}
case "$state" in _port_dispatch() {
extra) case "$words[2]" in
case "$words[2]" in provides)
provides) _files
_files ;;
;; search)
search) _message 'pattern'
_message 'pattern' ;;
;; help)
help) _describe -t actions 'Port actions' actions
_describe -t actions 'Port actions' actions ;;
;; select)
select) _call_function - _port_select
_call_function - _port_select ;;
;; contents|deactivate|setrequested|space|uninstall|unsetrequested)
contents|deactivate|setrequested|space|uninstall|unsetrequested) # Cache the list of installed ports.
# Cache the list of installed ports. if ( [[ ${+_port_installed_packages} -eq 0 ]] || _cache_invalid PORT_INSTALLED_PACKAGES ) &&
if ( [[ ${+_port_installed_packages} -eq 0 ]] || _cache_invalid PORT_INSTALLED_PACKAGES ) && ! _retrieve_cache PORT_INSTALLED_PACKAGES;
! _retrieve_cache PORT_INSTALLED_PACKAGES; then
then _port_installed_packages=( $(_call_program path-all "port echo all") )
_port_installed_packages=( $(_call_program path-all "port echo all") ) _store_cache PORT_INSTALLED_PACKAGES _port_installed_packages
_store_cache PORT_INSTALLED_PACKAGES _port_installed_packages fi
fi _alternative \
_alternative \ "ports:Installed ports:($_port_installed_packages)" \
"ports:Installed ports:($_port_installed_packages)" \ "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
"pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
"pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;;
;; upgrade)
upgrade) local outdated_packages
local outdated_packages outdated_packages=("${(f)$(port outdated | sed -e '1 d' -e 's/^\([[:graph:]]*\).*/\1/')}")
outdated_packages=("${(f)$(port outdated | sed -e '1 d' -e 's/^\([[:graph:]]*\).*/\1/')}") _describe "Outdated ports" outdated_packages
_describe "Outdated ports" outdated_packages ;;
;; *)
*) # Cache the list of all ports.
# Cache the list of all ports. if ( [[ ${+_port_available_packages} -eq 0 ]] || _cache_invalid PORT_AVAILABLE_PACKAGES ) &&
if ( [[ ${+_port_available_packages} -eq 0 ]] || _cache_invalid PORT_AVAILABLE_PACKAGES ) && ! _retrieve_cache PORT_AVAILABLE_PACKAGES;
! _retrieve_cache PORT_AVAILABLE_PACKAGES; then
then _port_available_packages=( $(_call_program path-all "port echo all") )
_port_available_packages=( $(_call_program path-all "port echo all") ) _store_cache PORT_AVAILABLE_PACKAGES _port_available_packages
_store_cache PORT_AVAILABLE_PACKAGES _port_available_packages fi
fi _alternative \
_alternative \ "ports:Available ports:($_port_available_packages)" \
"ports:Available ports:($_port_available_packages)" \ "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
"pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
"pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
;;
esac
;; ;;
esac esac
} }