From 33ea5c70d8fb880bdb8ed3c0fcf4ee69ddcd68fd Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:35:13 +0100 Subject: [PATCH] add interactive mode --- pkg/cli/commands/delete.go | 57 +++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index ce2cc40..4884464 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -1,15 +1,19 @@ package commands import ( + "context" "fmt" "strings" + "github.com/LazyBachelor/LazyPM/internal/models" "github.com/charmbracelet/huh" "github.com/spf13/cobra" ) // Variables for delete command flag. var confirmDelete bool +var deleteIDs []string +var deleteInteractive bool // deleteCmd represents the delete command. var deleteCmd = &cobra.Command{ @@ -18,8 +22,9 @@ var deleteCmd = &cobra.Command{ Long: `Delete an existing issue by its ID.`, Example: `pm delete pm-abc`, + ValidArgsFunction: completeIssues, + Aliases: []string{"del", "remove", "rm"}, - Args: cobra.ExactArgs(1), RunE: runDeleteCmd, } @@ -28,6 +33,17 @@ var deleteCmd = &cobra.Command{ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") + if deleteInteractive { + if err := runDeleteInteractive(); err != nil { + return err + } + return nil + } + + if deleteID == "" { + return fmt.Errorf("issue ID cannot be empty") + } + // Fetch the issue to ensure it exists before deletion. issue, err := svc.Beads.GetIssue(cmd.Context(), deleteID) if err != nil { @@ -62,8 +78,47 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { return nil } +func runDeleteInteractive() error { + options := []huh.Option[string]{} + + issues, err := svc.Beads.SearchIssues(context.Background(), "", models.IssueFilter{}) + if err != nil { + return fmt.Errorf("error fetching issues: %w", err) + } + + for _, issue := range issues { + desc := fmt.Sprintf("%s: %s", issue.ID, issue.Title) + options = append(options, huh.NewOption(desc, issue.ID)) + } + + form := huh.NewForm( + huh.NewGroup( + huh.NewMultiSelect[string]().Value(&deleteIDs). + Options(options...).Value(&deleteIDs). + Title("Select issues to delete"))).WithTheme(huh.ThemeBase()) + + if err := form.Run(); err != nil { + return fmt.Errorf("error running interactive form: %w", err) + } + + if len(deleteIDs) == 0 { + return fmt.Errorf("no issues selected for deletion") + } + + for _, id := range deleteIDs { + err := svc.Beads.DeleteIssue(context.Background(), id) + if err != nil { + return fmt.Errorf("error deleting issue with ID %s: %w", id, err) + } + fmt.Printf("Deleted issue with ID: %s\n", id) + } + + return nil +} + // init function to set up the delete command and its flags. func init() { + deleteCmd.Flags().BoolVarP(&deleteInteractive, "interactive", "i", false, "Delete issues interactively") deleteCmd.Flags().BoolVarP(&confirmDelete, "yes", "y", true, "Confirm deletion without prompt") rootCmd.AddCommand(deleteCmd)