Move some stuff to functions instead of case switches
This commit is contained in:
parent
cbccb3ada9
commit
7e9cfbc00f
51
_apk
51
_apk
|
@ -2,20 +2,6 @@
|
|||
|
||||
function _apk {
|
||||
|
||||
function _apk_packages {
|
||||
local -a packs
|
||||
if _cache_invalid cached_packs || ! _retrieve_cache cached_packs; then
|
||||
packs=(${$(/sbin/apk search)%-[[:digit:].]##-r[[:digit:]]##})
|
||||
_store_cache cached_packs packs
|
||||
fi
|
||||
compadd -a packs
|
||||
}
|
||||
|
||||
function _apk_cache {
|
||||
_describe 'subcommand' cache_subcmds
|
||||
}
|
||||
|
||||
|
||||
local -a global_opts=(
|
||||
"(-h --help)"{-h,--help}"[Print help information]"
|
||||
"(-i --interactive)"{-i,--interactive}"[Ask confirmation before performing certain operations]"
|
||||
|
@ -196,22 +182,33 @@ function _apk {
|
|||
local curcontext="$curcontext"
|
||||
local ret=1
|
||||
|
||||
function _apk_packages {
|
||||
local -a packs
|
||||
if _cache_invalid cached_packs || ! _retrieve_cache cached_packs; then
|
||||
packs=(${$(/sbin/apk search)%-[[:digit:].]##-r[[:digit:]]##})
|
||||
_store_cache cached_packs packs
|
||||
fi
|
||||
compadd -a packs
|
||||
}
|
||||
|
||||
function _apk_cache {
|
||||
_describe 'subcommand' cache_subcmds
|
||||
}
|
||||
|
||||
function _apk_subcmds {
|
||||
_describe 'subcommand' cmds
|
||||
}
|
||||
|
||||
function _apk_subcmd_args {
|
||||
local cmdvar="${words[1]}_args"
|
||||
_arguments -s -C ${(P)cmdvar} && ret=0
|
||||
}
|
||||
|
||||
# Main arguments
|
||||
_arguments -C -s \
|
||||
$global_opts \
|
||||
':subcommand:->subcmds' \
|
||||
'*::other:->other' && ret=0
|
||||
':subcommand:_apk_subcmds' \
|
||||
'*::subcommand:_apk_subcmd_args' && ret=0
|
||||
|
||||
# If no subcommands are given yet, complete those
|
||||
case "$state" in
|
||||
(subcmds)
|
||||
_describe 'subcommand' cmds
|
||||
;;
|
||||
# If they are given, call their respective function
|
||||
(other)
|
||||
local cmdvar="${words[1]}_args"
|
||||
_arguments -s -C ${(P)cmdvar} && ret=0
|
||||
;;
|
||||
esac
|
||||
return ret
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue