Improve bash completion for docker swarm {init,join} --{advertise,listen}-addr}

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2016-08-05 18:56:17 +02:00
parent 1ccd9d3137
commit 07f6655286

View file

@ -414,6 +414,20 @@ __docker_complete_resolved_hostname() {
COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
}
__docker_local_interfaces() {
command -v ip >/dev/null 2>&1 || return
ip addr show scope global 2>/dev/null | sed -n 's| \+inet \([0-9.]\+\).* \([^ ]\+\)|\1 \2|p'
}
__docker_complete_local_interfaces() {
local additional_interface
if [ "$1" = "--add" ] ; then
additional_interface="$2"
fi
COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) )
}
__docker_complete_capabilities() {
# The list of capabilities is defined in types.go, ALL was added manually.
COMPREPLY=( $( compgen -W "
@ -1836,15 +1850,21 @@ _docker_swarm() {
_docker_swarm_init() {
case "$prev" in
--listen-addr)
if [[ $cur == *: ]] ; then
COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
fi
return
;;
--advertise-addr)
if [[ $cur == *: ]] ; then
COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
else
__docker_complete_local_interfaces
__docker_nospace
fi
return
;;
--listen-addr)
if [[ $cur == *: ]] ; then
COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
else
__docker_complete_local_interfaces --add 0.0.0.0
__docker_nospace
fi
return
;;
@ -1859,19 +1879,25 @@ _docker_swarm_init() {
_docker_swarm_join() {
case "$prev" in
--token)
--advertise-addr)
if [[ $cur == *: ]] ; then
COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
else
__docker_complete_local_interfaces
__docker_nospace
fi
return
;;
--listen-addr)
if [[ $cur == *: ]] ; then
COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
else
__docker_complete_local_interfaces --add 0.0.0.0
__docker_nospace
fi
return
;;
--advertise-addr)
if [[ $cur == *: ]] ; then
COMPREPLY=( $( compgen -W "2377" -- "${cur##*:}" ) )
fi
--token)
return
;;
esac