github.com/kubeshop/testkube@v1.17.23/cmd/kubectl-testkube/commands/templates/delete.go (about) 1 package templates 2 3 import ( 4 "strings" 5 6 "github.com/spf13/cobra" 7 8 "github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common" 9 "github.com/kubeshop/testkube/pkg/ui" 10 ) 11 12 func NewDeleteTemplateCmd() *cobra.Command { 13 var name string 14 var selectors []string 15 16 cmd := &cobra.Command{ 17 18 Use: "template <templateName>", 19 Aliases: []string{"tp"}, 20 Short: "Delete a template.", 21 Long: `Delete a template and pass the template name to be deleted.`, 22 Run: func(cmd *cobra.Command, args []string) { 23 client, _, err := common.GetClient(cmd) 24 ui.ExitOnError("getting client", err) 25 26 if len(args) > 0 { 27 name = args[0] 28 err := client.DeleteTemplate(name) 29 ui.ExitOnError("deleting template: "+name, err) 30 ui.SuccessAndExit("Succesfully deleted template", name) 31 } 32 33 if len(selectors) != 0 { 34 selector := strings.Join(selectors, ",") 35 err := client.DeleteTemplates(selector) 36 ui.ExitOnError("deleting templates by labels: "+selector, err) 37 ui.SuccessAndExit("Succesfully deleted templates by labels", selector) 38 } 39 40 ui.Failf("Pass Template name or labels to delete by labels") 41 }, 42 } 43 44 cmd.Flags().StringVarP(&name, "name", "n", "", "unique template name, you can also pass it as first argument") 45 cmd.Flags().StringSliceVarP(&selectors, "label", "l", nil, "label key value pair: --label key1=value1") 46 47 return cmd 48 }