From 619883aba7a04f24a514c6f1d1c1490d55fa9e1e Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 25 Jan 2017 10:24:27 +0100 Subject: [PATCH 1/3] Add windows specific bash completion for `docker run|create` Signed-off-by: Harald Albers Upstream-commit: f2ee29ed96a9ba9c13cc1bec8b393565f5da9041 Component: engine --- .../engine/contrib/completion/bash/docker | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/components/engine/contrib/completion/bash/docker b/components/engine/contrib/completion/bash/docker index 8100e00845..08bbef40f1 100644 --- a/components/engine/contrib/completion/bash/docker +++ b/components/engine/contrib/completion/bash/docker @@ -442,6 +442,18 @@ __docker_is_experimental() { [ "$(__docker_q version -f '{{.Server.Experimental}}')" = "true" ] } +# __docker_daemon_os_is tests whether the currently configured Docker daemon runs +# on the operating system passed in as the first argument. +# It does so by querying the daemon for its OS. The result is cached for the duration +# of one invocation of bash completion so that this function can be used to test for +# several different operating systems without additional costs. +# Known operating systems: linux, windows. +__docker_daemon_os_is() { + local expected_os="$1" + local actual_os=${daemon_os=$(__docker_q version -f '{{.Server.Os}}')} + [ "$actual_os" = "$expected_os" ] +} + # __docker_pos_first_nonflag 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" @@ -1387,6 +1399,13 @@ _docker_container_run() { --volume -v --workdir -w " + __docker_daemon_os_is windows && options_with_args+=" + --cpu-count + --cpu-percent + --credentialspec + --io-maxbandwidth + --io-maxiops + " local boolean_options=" --disable-content-trust=false @@ -4132,7 +4151,7 @@ _docker() { --tlskey " - local host config + local host config daemon_os COMPREPLY=() local cur prev words cword From 19e6c32abb2fd4c3ef93b3e49a128d32b2724980 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 25 Jan 2017 10:29:50 +0100 Subject: [PATCH 2/3] Hide bash completion for `docker run|create|build --isolation` on non-windows Signed-off-by: Harald Albers Upstream-commit: fceaae95b5a61954ea40913b45b37b7dd1dd4d8a Component: engine --- .../engine/contrib/completion/bash/docker | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/components/engine/contrib/completion/bash/docker b/components/engine/contrib/completion/bash/docker index 08bbef40f1..ec27837c2a 100644 --- a/components/engine/contrib/completion/bash/docker +++ b/components/engine/contrib/completion/bash/docker @@ -1361,7 +1361,6 @@ _docker_container_run() { --ip --ip6 --ipc - --isolation --kernel-memory --label-file --label -l @@ -1405,6 +1404,7 @@ _docker_container_run() { --credentialspec --io-maxbandwidth --io-maxiops + --isolation " local boolean_options=" @@ -1523,8 +1523,10 @@ _docker_container_run() { return ;; --isolation) - __docker_complete_isolation - return + if __docker_daemon_os_is windows ; then + __docker_complete_isolation + return + fi ;; --link) case "$cur" in @@ -2028,7 +2030,6 @@ _docker_image_build() { --cpu-period --cpu-quota --file -f - --isolation --label --memory -m --memory-swap @@ -2037,6 +2038,9 @@ _docker_image_build() { --tag -t --ulimit " + __docker_daemon_os_is windows && options_with_args+=" + --isolation + " local boolean_options=" --compress @@ -2067,8 +2071,10 @@ _docker_image_build() { return ;; --isolation) - __docker_complete_isolation - return + if __docker_daemon_os_is windows ; then + __docker_complete_isolation + return + fi ;; --network) case "$cur" in From b0cadb1839db13f884b6082f53aff72ba4603b20 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 25 Jan 2017 10:33:09 +0100 Subject: [PATCH 3/3] Rename helper function in bash completion for consistency Signed-off-by: Harald Albers Upstream-commit: 93e43b42be7e600a266c17c64a3d718a0a4737a6 Component: engine --- components/engine/contrib/completion/bash/docker | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/engine/contrib/completion/bash/docker b/components/engine/contrib/completion/bash/docker index ec27837c2a..4ee42defd1 100644 --- a/components/engine/contrib/completion/bash/docker +++ b/components/engine/contrib/completion/bash/docker @@ -435,10 +435,10 @@ __docker_append_to_completions() { COMPREPLY=( ${COMPREPLY[@]/%/"$1"} ) } -# __docker_is_experimental tests whether the currently configured Docker daemon -# runs in experimental mode. If so, the function exits with 0 (true). +# __docker_daemon_is_experimental tests whether the currently configured Docker +# daemon runs in experimental mode. If so, the function exits with 0 (true). # Otherwise, or if the result cannot be determined, the exit value is 1 (false). -__docker_is_experimental() { +__docker_daemon_is_experimental() { [ "$(__docker_q version -f '{{.Server.Experimental}}')" = "true" ] } @@ -906,7 +906,7 @@ _docker_docker() { *) local counter=$( __docker_pos_first_nonflag "$(__docker_to_extglob "$global_options_with_args")" ) if [ $cword -eq $counter ]; then - __docker_is_experimental && commands+=(${experimental_commands[*]}) + __docker_daemon_is_experimental && commands+=(${experimental_commands[*]}) COMPREPLY=( $( compgen -W "${commands[*]} help" -- "$cur" ) ) fi ;; @@ -1955,7 +1955,7 @@ _docker_daemon() { } _docker_deploy() { - __docker_is_experimental && _docker_stack_deploy + __docker_daemon_is_experimental && _docker_stack_deploy } _docker_diff() { @@ -2052,7 +2052,7 @@ _docker_image_build() { --quiet -q --rm " - __docker_is_experimental && boolean_options+="--squash" + __docker_daemon_is_experimental && boolean_options+="--squash" local all_options="$options_with_args $boolean_options" @@ -3633,7 +3633,7 @@ _docker_stack() { _docker_stack_deploy() { case "$prev" in --bundle-file) - if __docker_is_experimental ; then + if __docker_daemon_is_experimental ; then _filedir dab return fi @@ -3647,7 +3647,7 @@ _docker_stack_deploy() { case "$cur" in -*) local options="--compose-file -c --help --with-registry-auth" - __docker_is_experimental && options+=" --bundle-file" + __docker_daemon_is_experimental && options+=" --bundle-file" COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) ;; esac