- Renamed config.json to metadata.json to clarify purpose (database metadata) - Fixed config.yaml/config.json conflict by making Viper explicitly load only config.yaml - Added automatic migration from config.json to metadata.json on first read - Fixed jsonOutput variable shadowing across 22 command files - Updated bd init to create both metadata.json and config.yaml template - Fixed 5 failing JSON output tests - All tests passing Resolves config file confusion and makes config.yaml work correctly. Closes #178 (global flags), addresses config issues from #193 Amp-Thread-ID: https://ampcode.com/threads/T-e6ac8192-e18f-4ed7-83bc-4a5986718bb7 Co-authored-by: Amp <amp@ampcode.com>
125 lines
3.1 KiB
Go
125 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/rpc"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
var staleCmd = &cobra.Command{
|
|
Use: "stale",
|
|
Short: "Show stale issues (not updated recently)",
|
|
Long: `Show issues that haven't been updated recently and may need attention.
|
|
|
|
This helps identify:
|
|
- In-progress issues with no recent activity (may be abandoned)
|
|
- Open issues that have been forgotten
|
|
- Issues that might be outdated or no longer relevant`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
days, _ := cmd.Flags().GetInt("days")
|
|
status, _ := cmd.Flags().GetString("status")
|
|
limit, _ := cmd.Flags().GetInt("limit")
|
|
// Use global jsonOutput set by PersistentPreRun
|
|
|
|
// Validate status if provided
|
|
if status != "" && status != "open" && status != "in_progress" && status != "blocked" {
|
|
fmt.Fprintf(os.Stderr, "Error: invalid status '%s'. Valid values: open, in_progress, blocked\n", status)
|
|
os.Exit(1)
|
|
}
|
|
|
|
filter := types.StaleFilter{
|
|
Days: days,
|
|
Status: status,
|
|
Limit: limit,
|
|
}
|
|
|
|
// If daemon is running, use RPC
|
|
if daemonClient != nil {
|
|
staleArgs := &rpc.StaleArgs{
|
|
Days: days,
|
|
Status: status,
|
|
Limit: limit,
|
|
}
|
|
|
|
resp, err := daemonClient.Stale(staleArgs)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
var issues []*types.Issue
|
|
if err := json.Unmarshal(resp.Data, &issues); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error parsing response: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if jsonOutput {
|
|
if issues == nil {
|
|
issues = []*types.Issue{}
|
|
}
|
|
outputJSON(issues)
|
|
return
|
|
}
|
|
|
|
displayStaleIssues(issues, days)
|
|
return
|
|
}
|
|
|
|
// Direct mode
|
|
ctx := context.Background()
|
|
issues, err := store.GetStaleIssues(ctx, filter)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if jsonOutput {
|
|
if issues == nil {
|
|
issues = []*types.Issue{}
|
|
}
|
|
outputJSON(issues)
|
|
return
|
|
}
|
|
|
|
displayStaleIssues(issues, days)
|
|
},
|
|
}
|
|
|
|
func displayStaleIssues(issues []*types.Issue, days int) {
|
|
if len(issues) == 0 {
|
|
green := color.New(color.FgGreen).SprintFunc()
|
|
fmt.Printf("\n%s No stale issues found (all active)\n\n", green("✨"))
|
|
return
|
|
}
|
|
|
|
yellow := color.New(color.FgYellow).SprintFunc()
|
|
fmt.Printf("\n%s Stale issues (%d not updated in %d+ days):\n\n", yellow("⏰"), len(issues), days)
|
|
|
|
now := time.Now()
|
|
for i, issue := range issues {
|
|
daysStale := int(now.Sub(issue.UpdatedAt).Hours() / 24)
|
|
fmt.Printf("%d. [P%d] %s: %s\n", i+1, issue.Priority, issue.ID, issue.Title)
|
|
fmt.Printf(" Status: %s, Last updated: %d days ago\n", issue.Status, daysStale)
|
|
if issue.Assignee != "" {
|
|
fmt.Printf(" Assignee: %s\n", issue.Assignee)
|
|
}
|
|
fmt.Println()
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
staleCmd.Flags().IntP("days", "d", 30, "Issues not updated in this many days")
|
|
staleCmd.Flags().StringP("status", "s", "", "Filter by status (open|in_progress|blocked)")
|
|
staleCmd.Flags().IntP("limit", "n", 50, "Maximum issues to show")
|
|
staleCmd.Flags().Bool("json", false, "Output JSON format")
|
|
|
|
rootCmd.AddCommand(staleCmd)
|
|
}
|