Skip to content
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