Use native formatting in bash completion of nodes

Completion of nodes now uses native Docker commands that were not available
when this function was created.

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2017-07-18 19:44:57 +02:00
parent 21b5bbe411
commit e391e34801
1 changed files with 10 additions and 5 deletions

View File

@ -441,18 +441,23 @@ __docker_complete_stacks() {
# precedence over the environment setting. # precedence over the environment setting.
# Completions may be added with `--add`, e.g. `--add self`. # Completions may be added with `--add`, e.g. `--add self`.
__docker_nodes() { __docker_nodes() {
local format
if [ "$DOCKER_COMPLETION_SHOW_NODE_IDS" = yes ] ; then
format='{{.ID}} {{.Hostname}}'
else
format='{{.Hostname}}'
fi
local add=() local add=()
local fields='$2' # default: node name only
[ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name
while true ; do while true ; do
case "$1" in case "$1" in
--id) --id)
fields='$1' # IDs only format='{{.ID}}'
shift shift
;; ;;
--name) --name)
fields='$2' # names only format='{{.Hostname}}'
shift shift
;; ;;
--add) --add)
@ -465,7 +470,7 @@ __docker_nodes() {
esac esac
done done
echo "$(__docker_q node ls "$@" | tr -d '*' | awk "NR>1 {print $fields}")" "${add[@]}" echo "$(__docker_q node ls --format "$format" "$@")" "${add[@]}"
} }
# __docker_complete_nodes applies completion of nodes based on the current # __docker_complete_nodes applies completion of nodes based on the current