Add bash completion for global `--context|-c` option

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2019-01-22 22:27:01 +01:00
parent 41bd8dad8c
commit 884d0783bd
1 changed files with 12 additions and 2 deletions

View File

@ -68,7 +68,7 @@ __docker_previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob shopt -s extglob
__docker_q() { __docker_q() {
docker ${host:+-H "$host"} ${config:+--config "$config"} 2>/dev/null "$@" docker ${host:+--host "$host"} ${config:+--config "$config"} ${context:+--context "$context"} 2>/dev/null "$@"
} }
# __docker_configs returns a list of configs. Additional options to # __docker_configs returns a list of configs. Additional options to
@ -1158,6 +1158,10 @@ _docker_docker() {
_filedir -d _filedir -d
return return
;; ;;
--context|-c)
__docker_complete_contexts
return
;;
--log-level|-l) --log-level|-l)
__docker_complete_log_levels __docker_complete_log_levels
return return
@ -5419,6 +5423,7 @@ _docker() {
" "
local global_options_with_args=" local global_options_with_args="
--config --config
--context -c
--host -H --host -H
--log-level -l --log-level -l
--tlscacert --tlscacert
@ -5431,7 +5436,7 @@ _docker() {
# variables to cache client info, populated on demand for performance reasons # variables to cache client info, populated on demand for performance reasons
local client_experimental stack_orchestrator_is_kubernetes stack_orchestrator_is_swarm local client_experimental stack_orchestrator_is_kubernetes stack_orchestrator_is_swarm
local host config local host config context
COMPREPLY=() COMPREPLY=()
local cur prev words cword local cur prev words cword
@ -5454,6 +5459,11 @@ _docker() {
(( counter++ )) (( counter++ ))
config="${words[$counter]}" config="${words[$counter]}"
;; ;;
# save context so that completion can use custom daemon
--context|-c)
(( counter++ ))
context="${words[$counter]}"
;;
$(__docker_to_extglob "$global_options_with_args") ) $(__docker_to_extglob "$global_options_with_args") )
(( counter++ )) (( counter++ ))
;; ;;