Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not prompt for user confirmation to delete context if not exists #705

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,17 +1089,18 @@ 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?")
if isAborted != nil {
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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/command/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Loading