From 918ff45c1a75f1ec307bb4d72fbb6ad609110b45 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Sat, 22 Oct 2016 10:03:43 -0700 Subject: [PATCH] Delegate bash completion for `docker {container,image} inspect` to parameterized function In #23614 `docker inspect` was semantically enhanced to inspect "everything". Therefore moving its logic to `_docker_container_inspect` was not correct. This commit moves it back to its original top-level location (`_docker_inspect`) so that it can be called by `_docker_{container,image}_inspect` and others (will be added in follow-up PRs). Parameterization was added in order to get caller-specific behavior. Signed-off-by: Harald Albers --- contrib/completion/bash/docker | 73 ++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 4fb01ea047..08b7b403e1 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -1021,34 +1021,7 @@ _docker_container_export() { } _docker_container_inspect() { - case "$prev" in - --format|-f) - return - ;; - --type) - COMPREPLY=( $( compgen -W "image container" -- "$cur" ) ) - return - ;; - - esac - - case "$cur" in - -*) - COMPREPLY=( $( compgen -W "--format -f --help --size -s --type" -- "$cur" ) ) - ;; - *) - case $(__docker_value_of_option --type) in - '') - __docker_complete_containers_and_images - ;; - container) - __docker_complete_containers_all - ;; - image) - __docker_complete_images - ;; - esac - esac + _docker_inspect --type container } _docker_container_kill() { @@ -2106,7 +2079,7 @@ _docker_image_import() { } _docker_image_inspect() { - _docker_inspect + _docker_inspect --type image } _docker_image_load() { @@ -2220,7 +2193,47 @@ _docker_info() { } _docker_inspect() { - _docker_container_inspect + local type + + if [ "$1" = "--type" ] ; then + type="$2" + else + type=$(__docker_value_of_option --type) + fi + + case "$prev" in + --format|-f) + return + ;; + --type) + if [ -z "$type" ] ; then + COMPREPLY=( $( compgen -W "image container" -- "$cur" ) ) + fi + return + ;; + esac + + case "$cur" in + -*) + local options="--format -f --help --size -s" + if [ -z "$type" ] ; then + options+=" --type" + fi + COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) + ;; + *) + case "$type" in + '') + __docker_complete_containers_and_images + ;; + container) + __docker_complete_containers_all + ;; + image) + __docker_complete_images + ;; + esac + esac } _docker_kill() {