feat(mail): accept multiple message IDs in delete command

Allow `gt mail delete` to accept multiple message IDs at once,
matching the existing behavior of archive, mark-read, and mark-unread.

Also adds --body as an alias for --message in mail reply.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/crew/max
2026-01-21 21:19:04 -08:00
committed by Steve Yegge
parent 94c2d71c13
commit 1dc31024ca
3 changed files with 37 additions and 13 deletions

View File

@@ -176,12 +176,16 @@ Exits silently with code 1 if no unread messages.`,
} }
var mailDeleteCmd = &cobra.Command{ var mailDeleteCmd = &cobra.Command{
Use: "delete <message-id>", Use: "delete <message-id> [message-id...]",
Short: "Delete a message", Short: "Delete messages",
Long: `Delete (acknowledge) a message. Long: `Delete (acknowledge) one or more messages.
This closes the message in beads.`, This closes the messages in beads.
Args: cobra.ExactArgs(1),
Examples:
gt mail delete hq-abc123
gt mail delete hq-abc123 hq-def456 hq-ghi789`,
Args: cobra.MinimumNArgs(1),
RunE: runMailDelete, RunE: runMailDelete,
} }
@@ -461,6 +465,7 @@ func init() {
// Reply flags // Reply flags
mailReplyCmd.Flags().StringVarP(&mailReplySubject, "subject", "s", "", "Override reply subject (default: Re: <original>)") mailReplyCmd.Flags().StringVarP(&mailReplySubject, "subject", "s", "", "Override reply subject (default: Re: <original>)")
mailReplyCmd.Flags().StringVarP(&mailReplyMessage, "message", "m", "", "Reply message body") mailReplyCmd.Flags().StringVarP(&mailReplyMessage, "message", "m", "", "Reply message body")
mailReplyCmd.Flags().StringVar(&mailReplyMessage, "body", "", "Reply message body (alias for --message)")
// Search flags // Search flags
mailSearchCmd.Flags().StringVar(&mailSearchFrom, "from", "", "Filter by sender address") mailSearchCmd.Flags().StringVar(&mailSearchFrom, "from", "", "Filter by sender address")

View File

@@ -224,11 +224,6 @@ func runMailPeek(cmd *cobra.Command, args []string) error {
} }
func runMailDelete(cmd *cobra.Command, args []string) error { func runMailDelete(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("msgID argument required")
}
msgID := args[0]
// Determine which inbox // Determine which inbox
address := detectSender() address := detectSender()
@@ -237,11 +232,32 @@ func runMailDelete(cmd *cobra.Command, args []string) error {
return err return err
} }
// Delete all specified messages
deleted := 0
var errors []string
for _, msgID := range args {
if err := mailbox.Delete(msgID); err != nil { if err := mailbox.Delete(msgID); err != nil {
return fmt.Errorf("deleting message: %w", err) errors = append(errors, fmt.Sprintf("%s: %v", msgID, err))
} else {
deleted++
}
} }
// Report results
if len(errors) > 0 {
fmt.Printf("%s Deleted %d/%d messages\n",
style.Bold.Render("⚠"), deleted, len(args))
for _, e := range errors {
fmt.Printf(" Error: %s\n", e)
}
return fmt.Errorf("failed to delete %d messages", len(errors))
}
if len(args) == 1 {
fmt.Printf("%s Message deleted\n", style.Bold.Render("✓")) fmt.Printf("%s Message deleted\n", style.Bold.Render("✓"))
} else {
fmt.Printf("%s Deleted %d messages\n", style.Bold.Render("✓"), deleted)
}
return nil return nil
} }

View File

@@ -80,6 +80,9 @@ func runMailThread(cmd *cobra.Command, args []string) error {
} }
func runMailReply(cmd *cobra.Command, args []string) error { func runMailReply(cmd *cobra.Command, args []string) error {
if mailReplyMessage == "" {
return fmt.Errorf("required flag \"message\" or \"body\" not set")
}
msgID := args[0] msgID := args[0]
// Get message body from positional arg or flag (positional takes precedence) // Get message body from positional arg or flag (positional takes precedence)