diff --git a/pkg/command/context.go b/pkg/command/context.go index 61fcc110b..0138ef0ef 100644 --- a/pkg/command/context.go +++ b/pkg/command/context.go @@ -1089,6 +1089,11 @@ func deleteCtx(_ *cobra.Command, args []string) error { name = args[0] } + ctx, err := config.GetContext(name) + if err != nil { + return err + } + if !unattended { isAborted := component.AskForConfirmation("Deleting the context entry from the config will remove it from the list of tracked contexts. " + "You will need to use `tanzu context create` to re-create this context. Are you sure you want to continue?") @@ -1096,10 +1101,6 @@ func deleteCtx(_ *cobra.Command, args []string) error { return nil } } - ctx, err := config.GetContext(name) - if err != nil { - return err - } installed, _, _, _ := getInstalledAndMissingContextPlugins() //nolint:dogsled log.Infof("Deleting entry for context '%s'", name) err = config.RemoveContext(name) diff --git a/pkg/command/context_test.go b/pkg/command/context_test.go index 99bd921bd..ee5b65a11 100644 --- a/pkg/command/context_test.go +++ b/pkg/command/context_test.go @@ -354,8 +354,8 @@ clusterOpts: unattended = true err = deleteCtx(cmd, []string{"fake-mc"}) Expect(err).ToNot(BeNil()) + Expect(err.Error()).ToNot(ContainSubstring("Deleting the context entry from the config will remove it from the list of tracked contexts. You will need to use `tanzu context create` to re-create this context. Are you sure you want to continue?")) Expect(err.Error()).To(ContainSubstring("context fake-mc not found")) - }) It("should delete context successfully if the config file has contexts available", func() { err = deleteCtx(cmd, []string{existingContext})