From 9b2ac7538d160b8928964fa0dde44ad7f3878fdc Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Sat, 23 May 2015 16:56:16 -0400 Subject: [PATCH] bashcompletions: suggest resources to delete in kubectl delete Before this patch if you type `kubectl delete [tab][tab]` you would get nothing. `kubectl delete pod [tab][tab]` would show the list of pods. This patch causes `kubectl delete [tab][tab]` to show the list of resources like pod, service, podtemplate, serviceaccount, etc --- contrib/completions/bash/kubectl | 15 +++++++++++++++ pkg/kubectl/cmd/delete.go | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index 5aaca9c1322..d914d40e575 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -420,6 +420,21 @@ _kubectl_delete() must_have_one_flag=() must_have_one_noun=() + must_have_one_noun+=("componentstatus") + must_have_one_noun+=("endpoints") + must_have_one_noun+=("event") + must_have_one_noun+=("limitrange") + must_have_one_noun+=("namespace") + must_have_one_noun+=("node") + must_have_one_noun+=("persistentvolume") + must_have_one_noun+=("persistentvolumeclaim") + must_have_one_noun+=("pod") + must_have_one_noun+=("podtemplate") + must_have_one_noun+=("replicationcontroller") + must_have_one_noun+=("resourcequota") + must_have_one_noun+=("secret") + must_have_one_noun+=("service") + must_have_one_noun+=("serviceaccount") } _kubectl_namespace() diff --git a/pkg/kubectl/cmd/delete.go b/pkg/kubectl/cmd/delete.go index f4ba900da75..66304647260 100644 --- a/pkg/kubectl/cmd/delete.go +++ b/pkg/kubectl/cmd/delete.go @@ -58,6 +58,9 @@ $ kubectl delete pods --all` ) func NewCmdDelete(f *cmdutil.Factory, out io.Writer) *cobra.Command { + p := kubectl.NewHumanReadablePrinter(false, false, false, []string{}) + validArgs := p.HandledResources() + cmd := &cobra.Command{ Use: "delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)])", Short: "Delete resources by filenames, stdin, resources and names, or by resources and label selector.", @@ -68,6 +71,7 @@ func NewCmdDelete(f *cmdutil.Factory, out io.Writer) *cobra.Command { err := RunDelete(f, out, cmd, args) cmdutil.CheckErr(err) }, + ValidArgs: validArgs, } usage := "Filename, directory, or URL to a file containing the resource to delete." kubectl.AddJsonFilenameFlag(cmd, usage)