From 2b6035722edf7390fd7195f8f364678b6a2f6fa7 Mon Sep 17 00:00:00 2001 From: knrt10 Date: Fri, 5 Jun 2020 14:08:14 +0530 Subject: [PATCH] Add `--confirm` flag to delete component without asking for confirmation Fixes #495 Signed-off-by: knrt10 --- cli/cmd/component-delete.go | 20 ++++++++++++-------- docs/cli/lokoctl_component_delete.md | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cli/cmd/component-delete.go b/cli/cmd/component-delete.go index a7557dc6e..6d6a55fdf 100644 --- a/cli/cmd/component-delete.go +++ b/cli/cmd/component-delete.go @@ -38,12 +38,14 @@ When run with no arguments, all components listed in the configuration are delet } var deleteNamespace bool +var confirmDeleteComponent bool // nolint:gochecknoinits func init() { componentCmd.AddCommand(componentDeleteCmd) pf := componentDeleteCmd.PersistentFlags() pf.BoolVarP(&deleteNamespace, "delete-namespace", "", false, "Delete namespace with component.") + pf.BoolVarP(&confirmDeleteComponent, "confirm", "", false, "Delete component without asking for confirmation.") } func runDelete(cmd *cobra.Command, args []string) { @@ -79,14 +81,16 @@ func runDelete(cmd *cobra.Command, args []string) { componentsObjects[i] = compObj } - if !askForConfirmation( - fmt.Sprintf( - "The following components will be deleted:\n\t%s\n\nAre you sure you want to proceed?", - strings.Join(componentsToDelete, "\n\t"), - ), - ) { - contextLogger.Info("Components deletion cancelled.") - return + if !confirmDeleteComponent { + if !askForConfirmation( + fmt.Sprintf( + "The following components will be deleted:\n\t%s\n\nAre you sure you want to proceed?", + strings.Join(componentsToDelete, "\n\t"), + ), + ) { + contextLogger.Info("Components deletion cancelled.") + return + } } kubeconfig, err := getKubeconfig() diff --git a/docs/cli/lokoctl_component_delete.md b/docs/cli/lokoctl_component_delete.md index c24c7765c..14872e2cb 100644 --- a/docs/cli/lokoctl_component_delete.md +++ b/docs/cli/lokoctl_component_delete.md @@ -14,6 +14,7 @@ lokoctl component delete [flags] ### Options ``` + --confirm Delete component without asking for confirmation. --delete-namespace Delete namespace with component. -h, --help help for delete ```