Skip to content

fix: confirm when deleting template #2866

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

Merged
merged 10 commits into from
Jul 11, 2022
Prev Previous commit
Next Next commit
populate templateNames from the interactive picker too
  • Loading branch information
ketang committed Jul 8, 2022
commit 5802c6b43fffe41c374ecc8e43c20b684310f345
20 changes: 11 additions & 9 deletions cli/templatedelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func templateDelete() *cobra.Command {

if len(args) > 0 {
templateNames = args

for _, templateName := range templateNames {
template, err := client.TemplateByName(ctx, organization.ID, templateName)
if err != nil {
return xerrors.Errorf("get template by name: %w", err)
}

templates = append(templates, template)
}

} else {
allTemplates, err := client.TemplatesByOrganization(ctx, organization.ID)
if err != nil {
Expand All @@ -58,19 +68,11 @@ func templateDelete() *cobra.Command {
for _, template := range allTemplates {
if template.Name == selection {
templates = append(templates, template)
templateNames = append(templateNames, template.Name)
}
}
}

for _, templateName := range templateNames {
template, err := client.TemplateByName(ctx, organization.ID, templateName)
if err != nil {
return xerrors.Errorf("get template by name: %w", err)
}

templates = append(templates, template)
}

// Confirm deletion of the template.
_, err = cliui.Prompt(cmd, cliui.PromptOptions{
Text: fmt.Sprintf("Delete these templates: %s?", cliui.Styles.Code.Render(strings.Join(templateNames, ", "))),
Expand Down