Add zsh completion for 'docker plugin' commands

Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
This commit is contained in:
Steve Durrheimer 2016-07-02 22:54:20 +02:00 committed by Tibor Vass
parent e31b0e691a
commit b1ea724ae6
1 changed files with 98 additions and 4 deletions

View File

@ -138,7 +138,7 @@ __docker_containers_names() {
__docker_get_containers all names "$@"
}
__docker_plugins() {
__docker_complete_info_plugins() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
emulate -L zsh
@ -451,7 +451,7 @@ __docker_network_complete_ls_filters() {
if compset -P '*='; then
case "${${words[-1]%=*}#*=}" in
(driver)
__docker_plugins Network && ret=0
__docker_complete_info_plugins Network && ret=0
;;
(id)
__docker_networks_ids && ret=0
@ -697,7 +697,6 @@ __docker_nodes() {
[[ $filter != "none") ]] && args=("-f $filter")
lines=(${(f)"$(_call_program commands docker $docker_options node ls $args)"})
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
@ -848,6 +847,84 @@ __docker_node_subcommand() {
# EO node
# BO plugin
__docker_complete_plugins() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines plugins
lines=(${(f)"$(_call_program commands docker $docker_options plugin ls)"})
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Name
for line in $lines; do
s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}"
plugins=($plugins $s)
done
_describe -t plugins-list "plugins" plugins "$@" && ret=0
return ret
}
__docker_plugin_commands() {
local -a _docker_plugin_subcommands
_docker_plugin_subcommands=(
"disable:Disable a plugin"
"enable:Enable a plugin"
"inspect:Return low-level information about a plugin"
"install:Install a plugin"
"ls:List plugins"
"push:Push a plugin"
"rm:Remove a plugin"
"set:Change settings for a plugin"
)
_describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands
}
__docker_plugin_subcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(disable|enable|inspect|install|ls|push|rm)
_arguments $(__docker_arguments) \
$opts_help \
"($help -)1:plugin:__docker_complete_plugins" && ret=0
;;
(set)
_arguments $(__docker_arguments) \
$opts_help \
"($help -)1:plugin:__docker_complete_plugins" \
"($help-)*:key=value: " && ret=0
;;
(help)
_arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0
;;
esac
return ret
}
# EO plugin
# BO swarm
__docker_swarm_commands() {
@ -927,7 +1004,7 @@ __docker_volume_complete_ls_filters() {
_describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0
;;
(driver)
__docker_plugins Volume && ret=0
__docker_complete_info_plugins Volume && ret=0
;;
(name)
__docker_volumes && ret=0
@ -1470,6 +1547,23 @@ __docker_subcommand() {
$opts_help \
"($help -)*:containers:__docker_runningcontainers" && ret=0
;;
(plugin)
local curcontext="$curcontext" state
_arguments $(__docker_arguments) \
$opts_help \
"($help -): :->command" \
"($help -)*:: :->option-or-argument" && ret=0
case $state in
(command)
__docker_plugin_commands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:docker-${words[-1]}:
__docker_plugin_subcommand && ret=0
;;
esac
;;
(port)
_arguments $(__docker_arguments) \
$opts_help \