Fix inconsistencies

Signed-off-by: Jean-Pierre Huynh <jean-pierre.huynh@ounet.fr>
This commit is contained in:
Jean-Pierre Huynh 2017-07-13 22:16:35 +01:00
parent ffe8509663
commit d7748e1b01
1 changed files with 23 additions and 18 deletions

View File

@ -1,9 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck disable=SC2155 # shellcheck disable=SC2016,SC2119,SC2155
# #
# Shellcheck ignore list: # Shellcheck ignore list:
# - SC2016: Expressions don't expand in single quotes, use double quotes for that.
# - SC2119: Use foo "$@" if function's $1 should mean script's $1.
# - SC2155: Declare and assign separately to avoid masking return values. # - SC2155: Declare and assign separately to avoid masking return values.
# #
# You can find more details for each warning at the following page:
# https://github.com/koalaman/shellcheck/wiki/<SCXXXX>
#
# bash completion file for core docker commands # bash completion file for core docker commands
# #
# This script provides completion of: # This script provides completion of:
@ -105,6 +110,7 @@ __docker_complete_containers_all() {
__docker_complete_containers "$@" --all __docker_complete_containers "$@" --all
} }
# shellcheck disable=SC2120
__docker_complete_containers_removable() { __docker_complete_containers_removable() {
__docker_complete_containers "$@" --filter status=created --filter status=exited __docker_complete_containers "$@" --filter status=created --filter status=exited
} }
@ -113,10 +119,12 @@ __docker_complete_containers_running() {
__docker_complete_containers "$@" --filter status=running __docker_complete_containers "$@" --filter status=running
} }
# shellcheck disable=SC2120
__docker_complete_containers_stopped() { __docker_complete_containers_stopped() {
__docker_complete_containers "$@" --filter status=exited __docker_complete_containers "$@" --filter status=exited
} }
# shellcheck disable=SC2120
__docker_complete_containers_unpauseable() { __docker_complete_containers_unpauseable() {
__docker_complete_containers "$@" --filter status=paused __docker_complete_containers "$@" --filter status=paused
} }
@ -146,7 +154,6 @@ __docker_images() {
esac esac
local repo_print_command local repo_print_command
# shellcheck disable=SC2016
if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then if [ "${DOCKER_COMPLETION_SHOW_TAGS:-yes}" = "yes" ]; then
repo_print_command='print $1; print $1":"$2' repo_print_command='print $1; print $1":"$2'
else else
@ -154,7 +161,6 @@ __docker_images() {
fi fi
local awk_script local awk_script
# shellcheck disable=SC2016
case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in case "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" in
all|non-intermediate) all|non-intermediate)
awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }' awk_script='NR>1 { print $3; if ($1 != "<none>") { '"$repo_print_command"' } }'
@ -219,7 +225,7 @@ __docker_complete_networks() {
COMPREPLY=( $(compgen -W "$(__docker_networks "$@")" -- "$current") ) COMPREPLY=( $(compgen -W "$(__docker_networks "$@")" -- "$current") )
} }
# shellcheck disable=SC2016,SC2128,SC2178 # shellcheck disable=SC2128,SC2178
__docker_complete_containers_in_network() { __docker_complete_containers_in_network() {
local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1") local containers=$(__docker_q network inspect -f '{{range $i, $c := .Containers}}{{$i}} {{$c.Name}} {{end}}' "$1")
COMPREPLY=( $(compgen -W "$containers" -- "$cur") ) COMPREPLY=( $(compgen -W "$containers" -- "$cur") )
@ -397,7 +403,6 @@ __docker_complete_stacks() {
# output to the IDs or names of matching items. This setting takes # output to the IDs or names of matching items. This setting takes
# 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`.
# shellcheck disable=SC2016
__docker_nodes() { __docker_nodes() {
local add=() local add=()
local fields='$2' # default: node name only local fields='$2' # default: node name only
@ -446,7 +451,6 @@ __docker_complete_nodes() {
# An optional first option `--id|--name` may be used to limit the # An optional first option `--id|--name` may be used to limit the
# output to the IDs or names of matching items. This setting takes # output to the IDs or names of matching items. This setting takes
# precedence over the environment setting. # precedence over the environment setting.
# shellcheck disable=SC2016
__docker_services() { __docker_services() {
local fields='$2' # default: service name only local fields='$2' # default: service name only
[ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name
@ -479,6 +483,7 @@ __docker_tasks() {
} }
# __docker_complete_services_and_tasks applies completion of services and task IDs. # __docker_complete_services_and_tasks applies completion of services and task IDs.
# shellcheck disable=SC2120
__docker_complete_services_and_tasks() { __docker_complete_services_and_tasks() {
COMPREPLY=( $(compgen -W "$(__docker_services "$@") $(__docker_tasks)" -- "$cur") ) COMPREPLY=( $(compgen -W "$(__docker_services "$@") $(__docker_tasks)" -- "$cur") )
} }
@ -1508,7 +1513,7 @@ _docker_container_rm() {
;; ;;
esac esac
done done
__docker_complete_containers_removable "$@" __docker_complete_containers_removable
;; ;;
esac esac
} }
@ -1851,7 +1856,7 @@ _docker_container_start() {
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;; ;;
*) *)
__docker_complete_containers_stopped "$@" __docker_complete_containers_stopped
;; ;;
esac esac
} }
@ -1912,7 +1917,7 @@ _docker_container_unpause() {
*) *)
local counter=$(__docker_pos_first_nonflag) local counter=$(__docker_pos_first_nonflag)
if [ "$cword" -eq "$counter" ]; then if [ "$cword" -eq "$counter" ]; then
__docker_complete_containers_unpauseable "$@" __docker_complete_containers_unpauseable
fi fi
;; ;;
esac esac
@ -2753,7 +2758,7 @@ _docker_network_connect() {
local counter=$( __docker_pos_first_nonflag "$( __docker_to_alternatives "$options_with_args" )" ) local counter=$( __docker_pos_first_nonflag "$( __docker_to_alternatives "$options_with_args" )" )
if [ "$cword" -eq "$counter" ]; then if [ "$cword" -eq "$counter" ]; then
__docker_complete_networks __docker_complete_networks
elif [ "$cword" -eq $((counter + 1)) ]; then elif [ "$cword" -eq "$((counter + 1))" ]; then
__docker_complete_containers_all __docker_complete_containers_all
fi fi
;; ;;
@ -2803,7 +2808,7 @@ _docker_network_disconnect() {
local counter=$(__docker_pos_first_nonflag) local counter=$(__docker_pos_first_nonflag)
if [ "$cword" -eq "$counter" ]; then if [ "$cword" -eq "$counter" ]; then
__docker_complete_networks __docker_complete_networks
elif [ "$cword" -eq $((counter + 1)) ]; then elif [ "$cword" -eq "$((counter + 1))" ]; then
__docker_complete_containers_in_network "$prev" __docker_complete_containers_in_network "$prev"
fi fi
;; ;;
@ -2983,7 +2988,7 @@ _docker_service_logs() {
*) *)
local counter=$(__docker_pos_first_nonflag '--since|--tail') local counter=$(__docker_pos_first_nonflag '--since|--tail')
if [ "$cword" -eq "$counter" ]; then if [ "$cword" -eq "$counter" ]; then
__docker_complete_services_and_tasks "$@" __docker_complete_services_and_tasks
fi fi
;; ;;
esac esac
@ -3748,7 +3753,7 @@ _docker_plugin_create() {
if [ "$cword" -eq "$counter" ]; then if [ "$cword" -eq "$counter" ]; then
# reponame # reponame
return return
elif [ "$cword" -eq $((counter + 1)) ]; then elif [ "$cword" -eq "$((counter + 1))" ]; then
_filedir -d _filedir -d
fi fi
;; ;;
@ -3908,7 +3913,7 @@ _docker_plugin_upgrade() {
if [ "$cword" -eq "$counter" ]; then if [ "$cword" -eq "$counter" ]; then
__docker_complete_plugins_installed __docker_complete_plugins_installed
__ltrim_colon_completions "$cur" __ltrim_colon_completions "$cur"
elif [ "$cword" -eq $((counter + 1)) ]; then elif [ "$cword" -eq "$((counter + 1))" ]; then
local plugin_images="$(__docker_plugins_installed)" local plugin_images="$(__docker_plugins_installed)"
COMPREPLY=( $(compgen -S : -W "${plugin_images%:*}" -- "$cur") ) COMPREPLY=( $(compgen -S : -W "${plugin_images%:*}" -- "$cur") )
__docker_nospace __docker_nospace
@ -3943,7 +3948,7 @@ _docker_restart() {
} }
_docker_rm() { _docker_rm() {
_docker_container_rm "$@" _docker_container_rm
} }
_docker_rmi() { _docker_rmi() {
@ -4269,7 +4274,7 @@ _docker_stack_up() {
_docker_start() { _docker_start() {
_docker_container_start "$@" _docker_container_start
} }
_docker_stats() { _docker_stats() {
@ -4444,7 +4449,7 @@ _docker_tag() {
} }
_docker_unpause() { _docker_unpause() {
_docker_container_unpause "$@" _docker_container_unpause
} }
_docker_update() { _docker_update() {