Add bash completion for kubernetes orchestrator

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2018-08-01 13:51:48 +02:00
parent 8ef01e869e
commit 08f8ee1320
1 changed files with 56 additions and 14 deletions

View File

@ -1075,6 +1075,23 @@ __docker_complete_signals() {
COMPREPLY=( $( compgen -W "${signals[*]} ${signals[*]#SIG}" -- "$( echo "$cur" | tr '[:lower:]' '[:upper:]')" ) )
}
__docker_complete_stack_orchestrator_options() {
case "$prev" in
--kubeconfig)
_filedir
return 0
;;
--namespace)
return 0
;;
--orchestrator)
COMPREPLY=( $( compgen -W "all kubernetes swarm" -- "$cur") )
return 0
;;
esac
return 1
}
__docker_complete_user_group() {
if [[ $cur == *:* ]] ; then
COMPREPLY=( $(compgen -g -- "${cur#*:}") )
@ -4403,11 +4420,15 @@ _docker_stack() {
remove
up
"
__docker_complete_stack_orchestrator_options && return
__docker_subcommands "$subcommands $aliases" && return
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
local options="--help --orchestrator"
__docker_stack_orchestrator_is kubernetes && options+=" --kubeconfig"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) )
@ -4416,12 +4437,12 @@ _docker_stack() {
}
_docker_stack_deploy() {
__docker_complete_stack_orchestrator_options && return
case "$prev" in
--bundle-file)
if __docker_daemon_is_experimental ; then
_filedir dab
return
fi
_filedir dab
return
;;
--compose-file|-c)
_filedir yml
@ -4435,13 +4456,14 @@ _docker_stack_deploy() {
case "$cur" in
-*)
local options="--compose-file -c --help"
local options="--compose-file -c --help --orchestrator"
__docker_daemon_is_experimental && __docker_stack_orchestrator_is swarm && options+=" --bundle-file"
__docker_stack_orchestrator_is kubernetes && options+=" --kubeconfig --namespace"
__docker_stack_orchestrator_is swarm && options+=" --prune --resolve-image --with-registry-auth"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;;
*)
local counter=$(__docker_pos_first_nonflag '--bundle-file|--compose-file|-c|--resolve-image')
local counter=$(__docker_pos_first_nonflag '--bundle-file|--compose-file|-c|--kubeconfig|--namespace|--orchestrator|--resolve-image')
if [ "$cword" -eq "$counter" ]; then
__docker_complete_stacks
fi
@ -4458,6 +4480,8 @@ _docker_stack_list() {
}
_docker_stack_ls() {
__docker_complete_stack_orchestrator_options && return
case "$prev" in
--format)
return
@ -4466,7 +4490,9 @@ _docker_stack_ls() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--format --help" -- "$cur" ) )
local options="--format --help --orchestrator"
__docker_stack_orchestrator_is kubernetes && options+=" --all-namespaces --kubeconfig --namespace"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;;
esac
}
@ -4488,6 +4514,8 @@ _docker_stack_ps() {
;;
esac
__docker_complete_stack_orchestrator_options && return
case "$prev" in
--filter|-f)
COMPREPLY=( $( compgen -S = -W "id name desired-state" -- "$cur" ) )
@ -4501,10 +4529,12 @@ _docker_stack_ps() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--filter -f --format --help --no-resolve --no-trunc --quiet -q" -- "$cur" ) )
local options="--filter -f --format --help --no-resolve --no-trunc --orchestrator --quiet -q"
__docker_stack_orchestrator_is kubernetes && options+=" --all-namespaces --kubeconfig --namespace"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;;
*)
local counter=$(__docker_pos_first_nonflag '--filter|-f')
local counter=$(__docker_pos_first_nonflag '--all-namespaces|--filter|-f|--format|--kubeconfig|--namespace')
if [ "$cword" -eq "$counter" ]; then
__docker_complete_stacks
fi
@ -4517,9 +4547,13 @@ _docker_stack_remove() {
}
_docker_stack_rm() {
__docker_complete_stack_orchestrator_options && return
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
local options="--help --orchestrator"
__docker_stack_orchestrator_is kubernetes && options+=" --kubeconfig --namespace"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;;
*)
__docker_complete_stacks
@ -4543,6 +4577,8 @@ _docker_stack_services() {
;;
esac
__docker_complete_stack_orchestrator_options && return
case "$prev" in
--filter|-f)
COMPREPLY=( $( compgen -S = -W "id label name" -- "$cur" ) )
@ -4556,10 +4592,12 @@ _docker_stack_services() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--filter -f --format --help --quiet -q" -- "$cur" ) )
local options="--filter -f --format --help --orchestrator --quiet -q"
__docker_stack_orchestrator_is kubernetes && options+=" --kubeconfig --namespace"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;;
*)
local counter=$(__docker_pos_first_nonflag '--filter|-f|--format')
local counter=$(__docker_pos_first_nonflag '--filter|-f|--format|--kubeconfig|--namespace|--orchestrator')
if [ "$cword" -eq "$counter" ]; then
__docker_complete_stacks
fi
@ -4826,6 +4864,8 @@ _docker_top() {
}
_docker_version() {
__docker_complete_stack_orchestrator_options && return
case "$prev" in
--format|-f)
return
@ -4834,7 +4874,9 @@ _docker_version() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
local options="--format -f --help"
__docker_stack_orchestrator_is kubernetes && options+=" --kubeconfig"
COMPREPLY=( $( compgen -W "$options" -- "$cur" ) )
;;
esac
}