mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #23830 from sttts/sttts-bash-completion-override-flags
Automatic merge from submit-queue Add awareness of more override flags in bash-completion Add awareness during completion for - `--kubeconfig` - `--cluster` - `--user` - `--context` - `--server` TODO: - [ ] ~~add completion for the upper flags themselves~~ (out of scope) <!-- Reviewable:start --> --- This change is [<img src="http://reviewable.k8s.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](http://reviewable.k8s.io/reviews/kubernetes/kubernetes/23830) <!-- Reviewable:end -->
This commit is contained in:
		@@ -32,30 +32,35 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	bash_completion_func = `# call kubectl get $1,
 | 
						bash_completion_func = `# call kubectl get $1,
 | 
				
			||||||
__kubectl_namespace_flag()
 | 
					__kubectl_override_flag_list=(kubeconfig cluster user context namespace server)
 | 
				
			||||||
 | 
					__kubectl_override_flags()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    local ret two_word_ns
 | 
					    local ${__kubectl_override_flag_list[*]} two_word_of of
 | 
				
			||||||
    ret=""
 | 
					 | 
				
			||||||
    two_word_ns=false
 | 
					 | 
				
			||||||
    for w in "${words[@]}"; do
 | 
					    for w in "${words[@]}"; do
 | 
				
			||||||
        if [ "$two_word_ns" = true ]; then
 | 
					        if [ -n "${two_word_of}" ]; then
 | 
				
			||||||
            ret="--namespace=${w}"
 | 
					            eval "${two_word_of}=\"--${two_word_of}=\${w}\""
 | 
				
			||||||
            two_word_ns=false
 | 
					            two_word_of=
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
        fi
 | 
					        fi
 | 
				
			||||||
        case "${w}" in
 | 
					        for of in "${__kubectl_override_flag_list[@]}"; do
 | 
				
			||||||
            --namespace=*)
 | 
					            case "${w}" in
 | 
				
			||||||
                ret=${w}
 | 
					                --${of}=*)
 | 
				
			||||||
                ;;
 | 
					                    eval "${of}=\"--${of}=\${w}\""
 | 
				
			||||||
            --namespace)
 | 
					                    ;;
 | 
				
			||||||
                two_word_ns=true
 | 
					                --${of})
 | 
				
			||||||
                ;;
 | 
					                    two_word_of="${of}"
 | 
				
			||||||
            --all-namespaces)
 | 
					                    ;;
 | 
				
			||||||
                ret=${w}
 | 
					            esac
 | 
				
			||||||
                ;;
 | 
					        done
 | 
				
			||||||
        esac
 | 
					        if [ "${w}" == "--all-namespaces" ]; then
 | 
				
			||||||
 | 
					            namespace="--all-namespaces"
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					    done
 | 
				
			||||||
 | 
					    for of in "${__kubectl_override_flag_list[@]}"; do
 | 
				
			||||||
 | 
					        if eval "test -n \"\$${of}\""; then
 | 
				
			||||||
 | 
					            eval "echo \${${of}}"
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
    done
 | 
					    done
 | 
				
			||||||
    echo $ret
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
__kubectl_get_namespaces()
 | 
					__kubectl_get_namespaces()
 | 
				
			||||||
@@ -72,7 +77,7 @@ __kubectl_parse_get()
 | 
				
			|||||||
    local template
 | 
					    local template
 | 
				
			||||||
    template="{{ range .items  }}{{ .metadata.name }} {{ end }}"
 | 
					    template="{{ range .items  }}{{ .metadata.name }} {{ end }}"
 | 
				
			||||||
    local kubectl_out
 | 
					    local kubectl_out
 | 
				
			||||||
    if kubectl_out=$(kubectl get $(__kubectl_namespace_flag) -o template --template="${template}" "$1" 2>/dev/null); then
 | 
					    if kubectl_out=$(kubectl get $(__kubectl_override_flags) -o template --template="${template}" "$1" 2>/dev/null); then
 | 
				
			||||||
        COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
 | 
					        COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user