Add bash completion for `dockerd --metrics-addr`

`--metrics-addr` does not accept network interface names.
Therefore `__docker_local_interfaces` was refined for this feature to
optionally exclude interface names.

Note that although `--metrics-addr` is experimental, it cannot be
selectively enabled in bash completion because the test for the daemon
running in experimental mode requires a running daemon. As this
completion pertains to starting the daemon, this requirement is not met.

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2017-07-03 14:37:51 +02:00
parent 74a5d1af86
commit 0ea31afd57
1 changed files with 31 additions and 2 deletions

View File

@ -636,18 +636,40 @@ __docker_complete_resolved_hostname() {
COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') )
}
# __docker_local_interfaces returns a list of the names and addresses of all
# local network interfaces.
# If `--ip-only` is passed as a first argument, only addresses are returned.
__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'
local format
if [ "$1" = "--ip-only" ] ; then
format='\1'
shift
else
format='\1 \2'
fi
ip addr show scope global 2>/dev/null | sed -n "s| \+inet \([0-9.]\+\).* \([^ ]\+\)|$format|p"
}
# __docker_complete_local_interfaces applies completion of the names and addresses of all
# local network interfaces based on the current value of `$cur`.
# An additional value can be added to the possible completions with an `--add` argument.
__docker_complete_local_interfaces() {
local additional_interface
if [ "$1" = "--add" ] ; then
additional_interface="$2"
shift 2
fi
COMPREPLY=( $( compgen -W "$(__docker_local_interfaces) $additional_interface" -- "$cur" ) )
COMPREPLY=( $( compgen -W "$(__docker_local_interfaces "$@") $additional_interface" -- "$cur" ) )
}
# __docker_complete_local_ips applies completion of the addresses of all local network
# interfaces based on the current value of `$cur`.
__docker_complete_local_ips() {
__docker_complete_local_interfaces --ip-only
}
# __docker_complete_capabilities_addable completes Linux capabilities which are
@ -2006,6 +2028,7 @@ _docker_daemon() {
--log-opt
--max-concurrent-downloads
--max-concurrent-uploads
--metrics-addr
--mtu
--oom-score-adjust
--pidfile -p
@ -2130,6 +2153,12 @@ _docker_daemon() {
__docker_complete_log_options
return
;;
--metrics-addr)
__docker_complete_local_ips
__docker_append_to_completions ":"
__docker_nospace
return
;;
--seccomp-profile)
_filedir json
return