list: extract command to separate file
This commit is contained in:
72
cmd/bd/list.go
Normal file
72
cmd/bd/list.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -1031,68 +1031,6 @@ func init() {
|
|||||||
rootCmd.AddCommand(showCmd)
|
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{
|
var updateCmd = &cobra.Command{
|
||||||
Use: "update [id]",
|
Use: "update [id]",
|
||||||
Short: "Update an issue",
|
Short: "Update an issue",
|
||||||
|
|||||||
Reference in New Issue
Block a user