feat(mail): add --all flag to 'gt mail inbox' command

Adds --all/-a flag as a semantic complement to --unread. While the
default behavior already shows all messages, --all makes the intent
explicit when viewing the complete inbox.

The flags are mutually exclusive - using both --all and --unread
returns an error.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
dementus
2026-01-20 20:37:19 -08:00
committed by beads/crew/emma
parent cd347dfdf9
commit d610d444d7
2 changed files with 14 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ var (
mailInboxJSON bool
mailReadJSON bool
mailInboxUnread bool
mailInboxAll bool
mailInboxIdentity string
mailCheckInject bool
mailCheckJSON bool
@@ -138,8 +139,13 @@ var mailInboxCmd = &cobra.Command{
If no address is specified, shows the current context's inbox.
Use --identity for polecats to explicitly specify their identity.
By default, shows all messages. Use --unread to filter to unread only,
or --all to explicitly show all messages (read and unread).
Examples:
gt mail inbox # Current context (auto-detected)
gt mail inbox --all # Explicitly show all messages
gt mail inbox --unread # Show only unread messages
gt mail inbox mayor/ # Mayor's inbox
gt mail inbox greenplace/Toast # Polecat's inbox
gt mail inbox --identity greenplace/Toast # Explicit polecat identity`,
@@ -433,6 +439,7 @@ func init() {
// Inbox flags
mailInboxCmd.Flags().BoolVar(&mailInboxJSON, "json", false, "Output as JSON")
mailInboxCmd.Flags().BoolVarP(&mailInboxUnread, "unread", "u", false, "Show only unread messages")
mailInboxCmd.Flags().BoolVarP(&mailInboxAll, "all", "a", false, "Show all messages (read and unread)")
mailInboxCmd.Flags().StringVar(&mailInboxIdentity, "identity", "", "Explicit identity for inbox (e.g., greenplace/Toast)")
mailInboxCmd.Flags().StringVar(&mailInboxIdentity, "address", "", "Alias for --identity")

View File

@@ -30,6 +30,11 @@ func getMailbox(address string) (*mail.Mailbox, error) {
}
func runMailInbox(cmd *cobra.Command, args []string) error {
// Check for mutually exclusive flags
if mailInboxAll && mailInboxUnread {
return errors.New("--all and --unread are mutually exclusive")
}
// Determine which inbox to check (priority: --identity flag, positional arg, auto-detect)
address := ""
if mailInboxIdentity != "" {
@@ -46,6 +51,8 @@ func runMailInbox(cmd *cobra.Command, args []string) error {
}
// Get messages
// --all is the default behavior (shows all messages)
// --unread filters to only unread messages
var messages []*mail.Message
if mailInboxUnread {
messages, err = mailbox.ListUnread()