Merge pull request #18828 from albers/completion-plugins

Use computed plugin lists in bash completion
This commit is contained in:
David Calavera 2015-12-21 09:57:48 -08:00
commit 88c4d4a943

View file

@ -153,8 +153,11 @@ __docker_networks() {
# Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs.
local fields='$2'
[ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2'
local networks=$(__docker_q network ls --no-trunc | awk "NR>1 {print $fields}")
COMPREPLY=( $(compgen -W "$networks" -- "$cur") )
__docker_q network ls --no-trunc | awk "NR>1 {print $fields}"
}
__docker_complete_networks() {
COMPREPLY=( $(compgen -W "$(__docker_complete_networks)" -- "$cur") )
}
__docker_containers_in_network() {
@ -166,6 +169,14 @@ __docker_volumes() {
COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") )
}
__docker_plugins() {
__docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $1: //p"
}
__docker_complete_plugins() {
COMPREPLY=( $(compgen -W "$(__docker_plugins $1)" -- "$cur") )
}
# Finds the position of the first word that is neither option nor an option's argument.
# If there are options that require arguments, you should pass a glob describing those
# options, e.g. "--option1|-o|--option2"
@ -1103,7 +1114,7 @@ _docker_network_connect() {
*)
local counter=$(__docker_pos_first_nonflag)
if [ $cword -eq $counter ]; then
__docker_networks
__docker_complete_networks
elif [ $cword -eq $(($counter + 1)) ]; then
__docker_containers_running
fi
@ -1121,9 +1132,11 @@ _docker_network_create() {
return
;;
--driver|-d)
# no need to suggest drivers that allow one instance only
# (host, null)
COMPREPLY=( $( compgen -W "bridge overlay" -- "$cur" ) )
local plugins=" $(__docker_plugins Network) "
# remove drivers that allow one instance only
plugins=${plugins/ host / }
plugins=${plugins/ null / }
COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
return
;;
esac
@ -1143,7 +1156,7 @@ _docker_network_disconnect() {
*)
local counter=$(__docker_pos_first_nonflag)
if [ $cword -eq $counter ]; then
__docker_networks
__docker_complete_networks
elif [ $cword -eq $(($counter + 1)) ]; then
__docker_containers_in_network "$prev"
fi
@ -1163,7 +1176,7 @@ _docker_network_inspect() {
COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
;;
*)
__docker_networks
__docker_complete_networks
esac
}
@ -1535,7 +1548,7 @@ _docker_run() {
__docker_containers_all
;;
*)
COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") )
COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
if [ "${COMPREPLY[*]}" = "container:" ] ; then
__docker_nospace
fi
@ -1572,7 +1585,7 @@ _docker_run() {
return
;;
--volume-driver)
COMPREPLY=( $( compgen -W "local" -- "$cur" ) )
__docker_complete_plugins Volume
return
;;
--volumes-from)
@ -1731,7 +1744,7 @@ _docker_version() {
_docker_volume_create() {
case "$prev" in
--driver|-d)
COMPREPLY=( $( compgen -W "local" -- "$cur" ) )
__docker_complete_plugins Volume
return
;;
--name|--opt|-o)