Fix nil pointer crash in bd reopen command (bd-133)
- Add daemon RPC support to reopen command - Check daemonClient != nil first, use RPC if available - Fall back to direct store access with nil check - Reopened bd-55 for remaining cyclomatic complexity work Amp-Thread-ID: https://ampcode.com/threads/T-2ea7e226-4672-4a49-96b4-81ab5cf953cd Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -2,11 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/beads/internal/rpc"
|
||||
"github.com/steveyegge/beads/internal/types"
|
||||
)
|
||||
|
||||
@@ -22,6 +24,54 @@ This is more explicit than 'bd update --status open' and emits a Reopened event.
|
||||
|
||||
ctx := context.Background()
|
||||
reopenedIssues := []*types.Issue{}
|
||||
|
||||
// If daemon is running, use RPC
|
||||
if daemonClient != nil {
|
||||
for _, id := range args {
|
||||
openStatus := string(types.StatusOpen)
|
||||
updateArgs := &rpc.UpdateArgs{
|
||||
ID: id,
|
||||
Status: &openStatus,
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error reopening %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// TODO: Add reason as a comment once RPC supports AddComment
|
||||
if reason != "" {
|
||||
fmt.Fprintf(os.Stderr, "Warning: reason not supported in daemon mode yet\n")
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
var issue types.Issue
|
||||
if err := json.Unmarshal(resp.Data, &issue); err == nil {
|
||||
reopenedIssues = append(reopenedIssues, &issue)
|
||||
}
|
||||
} else {
|
||||
blue := color.New(color.FgBlue).SprintFunc()
|
||||
reasonMsg := ""
|
||||
if reason != "" {
|
||||
reasonMsg = ": " + reason
|
||||
}
|
||||
fmt.Printf("%s Reopened %s%s\n", blue("↻"), id, reasonMsg)
|
||||
}
|
||||
}
|
||||
|
||||
if jsonOutput && len(reopenedIssues) > 0 {
|
||||
outputJSON(reopenedIssues)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Fall back to direct storage access
|
||||
if store == nil {
|
||||
fmt.Fprintln(os.Stderr, "Error: database not initialized")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for _, id := range args {
|
||||
// UpdateIssue automatically clears closed_at when status changes from closed
|
||||
updates := map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user