From ff953751d342f7815060593d14763030af77621c Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 1 Aug 2018 10:48:40 +0200 Subject: [PATCH] Add support for orchestrator specific bash completions Signed-off-by: Harald Albers --- contrib/completion/bash/docker | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 3fdb905cb5..e0fa076528 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -584,6 +584,31 @@ __docker_daemon_os_is() { [ "$actual_os" = "$expected_os" ] } +# __docker_stack_orchestrator_is tests whether the client is configured to use +# the orchestrator that is passed in as the first argument. +__docker_stack_orchestrator_is() { + case "$1" in + kubernetes) + if [ -z "$stack_orchestrator_is_kubernetes" ] ; then + __docker_q stack ls --help | grep -qe --namespace + stack_orchestrator_is_kubernetes=$? + fi + return $stack_orchestrator_is_kubernetes + ;; + swarm) + if [ -z "$stack_orchestrator_is_swarm" ] ; then + __docker_q stack deploy --help | grep -qe "with-registry-auth" + stack_orchestrator_is_swarm=$? + fi + return $stack_orchestrator_is_swarm + ;; + *) + return 1 + ;; + + esac +} + # __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" @@ -5038,6 +5063,9 @@ _docker() { local host config daemon_os + # variables to cache client info, populated on demand for performance reasons + local stack_orchestrator_is_kubernetes stack_orchestrator_is_swarm + COMPREPLY=() local cur prev words cword _get_comp_words_by_ref -n : cur prev words cword