diff --git a/cmd/bd/list.go b/cmd/bd/list.go new file mode 100644 index 00000000..5ec1959a --- /dev/null +++ b/cmd/bd/list.go @@ -0,0 +1,72 @@ +package main + +import ( + "context" + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/steveyegge/beads/internal/types" +) + +var listCmd = &cobra.Command{ + Use: "list", + Short: "List issues", + Run: func(cmd *cobra.Command, args []string) { + status, _ := cmd.Flags().GetString("status") + assignee, _ := cmd.Flags().GetString("assignee") + issueType, _ := cmd.Flags().GetString("type") + limit, _ := cmd.Flags().GetInt("limit") + + filter := types.IssueFilter{ + Limit: limit, + } + if status != "" { + s := types.Status(status) + filter.Status = &s + } + // Use Changed() to properly handle P0 (priority=0) + if cmd.Flags().Changed("priority") { + priority, _ := cmd.Flags().GetInt("priority") + filter.Priority = &priority + } + if assignee != "" { + filter.Assignee = &assignee + } + if issueType != "" { + t := types.IssueType(issueType) + filter.IssueType = &t + } + + ctx := context.Background() + issues, err := store.SearchIssues(ctx, "", filter) + if err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } + + if jsonOutput { + outputJSON(issues) + return + } + + fmt.Printf("\nFound %d issues:\n\n", len(issues)) + for _, issue := range issues { + fmt.Printf("%s [P%d] [%s] %s\n", issue.ID, issue.Priority, issue.IssueType, issue.Status) + fmt.Printf(" %s\n", issue.Title) + if issue.Assignee != "" { + fmt.Printf(" Assignee: %s\n", issue.Assignee) + } + fmt.Println() + } + }, +} + +func init() { + listCmd.Flags().StringP("status", "s", "", "Filter by status") + listCmd.Flags().IntP("priority", "p", 0, "Filter by priority") + listCmd.Flags().StringP("assignee", "a", "", "Filter by assignee") + listCmd.Flags().StringP("type", "t", "", "Filter by type") + listCmd.Flags().IntP("limit", "n", 0, "Limit results") + rootCmd.AddCommand(listCmd) +} diff --git a/cmd/bd/main.go b/cmd/bd/main.go index 20046cad..3143cc0d 100644 --- a/cmd/bd/main.go +++ b/cmd/bd/main.go @@ -1031,68 +1031,6 @@ func init() { rootCmd.AddCommand(showCmd) } -var listCmd = &cobra.Command{ - Use: "list", - Short: "List issues", - Run: func(cmd *cobra.Command, args []string) { - status, _ := cmd.Flags().GetString("status") - assignee, _ := cmd.Flags().GetString("assignee") - issueType, _ := cmd.Flags().GetString("type") - limit, _ := cmd.Flags().GetInt("limit") - - filter := types.IssueFilter{ - Limit: limit, - } - if status != "" { - s := types.Status(status) - filter.Status = &s - } - // Use Changed() to properly handle P0 (priority=0) - if cmd.Flags().Changed("priority") { - priority, _ := cmd.Flags().GetInt("priority") - filter.Priority = &priority - } - if assignee != "" { - filter.Assignee = &assignee - } - if issueType != "" { - t := types.IssueType(issueType) - filter.IssueType = &t - } - - ctx := context.Background() - issues, err := store.SearchIssues(ctx, "", filter) - if err != nil { - fmt.Fprintf(os.Stderr, "Error: %v\n", err) - os.Exit(1) - } - - if jsonOutput { - outputJSON(issues) - return - } - - fmt.Printf("\nFound %d issues:\n\n", len(issues)) - for _, issue := range issues { - fmt.Printf("%s [P%d] [%s] %s\n", issue.ID, issue.Priority, issue.IssueType, issue.Status) - fmt.Printf(" %s\n", issue.Title) - if issue.Assignee != "" { - fmt.Printf(" Assignee: %s\n", issue.Assignee) - } - fmt.Println() - } - }, -} - -func init() { - listCmd.Flags().StringP("status", "s", "", "Filter by status") - listCmd.Flags().IntP("priority", "p", 0, "Filter by priority") - listCmd.Flags().StringP("assignee", "a", "", "Filter by assignee") - listCmd.Flags().StringP("type", "t", "", "Filter by type") - listCmd.Flags().IntP("limit", "n", 0, "Limit results") - rootCmd.AddCommand(listCmd) -} - var updateCmd = &cobra.Command{ Use: "update [id]", Short: "Update an issue",