showIssueAsOf reported each failed AS OF lookup on stderr and continued, but never counted what it read and returned nil, so a bad ref (an instant or a versioned-history address the Dolt AS OF read does not take, an unknown branch or commit) or an issue absent at the ref exited 0 with an empty stdout, under --json too. Its proxied-server twin, runShowProxiedAsOf, returned nothing and its dispatcher returned nil. Both now count the issues they read and, when that is zero, end the way plain bd show ends a batch that found nothing: show's JSON error envelope on stdout under --json, a bare exit 1 otherwise, with the per-id reasons still on stderr. A batch that reads at least one issue still exits 0, as plain show's does. The read itself is unchanged (Dolt AS OF). Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
147 lines
4.2 KiB
Go
147 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
"github.com/steveyegge/beads/internal/uimd"
|
|
)
|
|
|
|
// showIssueChildren displays only the children of the specified issue(s)
|
|
func showIssueChildren(ctx context.Context, args []string, jsonOut bool, shortMode bool) error {
|
|
// Collect all children for all issues
|
|
allChildren := make(map[string][]*types.IssueWithDependencyMetadata)
|
|
|
|
// Process each issue to get its children
|
|
processIssue := func(issueID string, issueStore storage.DoltStorage) error {
|
|
// Initialize entry so "no children" message can be shown
|
|
if _, exists := allChildren[issueID]; !exists {
|
|
allChildren[issueID] = []*types.IssueWithDependencyMetadata{}
|
|
}
|
|
|
|
// Get all dependents with metadata so we can filter for children
|
|
refs, err := issueStore.GetDependentsWithMetadata(ctx, issueID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// Filter for only parent-child relationships
|
|
for _, ref := range refs {
|
|
if ref.DependencyType == types.DepParentChild {
|
|
allChildren[issueID] = append(allChildren[issueID], ref)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Process each arg via routing-aware resolution
|
|
for _, id := range args {
|
|
result, err := resolveAndGetIssueWithRouting(ctx, store, id)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
|
|
continue
|
|
}
|
|
if result == nil || result.Issue == nil {
|
|
if result != nil {
|
|
result.Close()
|
|
}
|
|
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
|
|
continue
|
|
}
|
|
if err := processIssue(result.ResolvedID, result.Store); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error getting children for %s: %v\n", id, err)
|
|
}
|
|
result.Close()
|
|
}
|
|
|
|
// Output results
|
|
if jsonOut {
|
|
return outputJSON(allChildren)
|
|
}
|
|
|
|
// Display children
|
|
for issueID, children := range allChildren {
|
|
if len(children) == 0 {
|
|
fmt.Printf("%s: No children found\n", ui.RenderAccent(issueID))
|
|
continue
|
|
}
|
|
|
|
fmt.Printf("%s Children of %s (%d):\n", ui.RenderAccent("↳"), issueID, len(children))
|
|
for _, child := range children {
|
|
if shortMode {
|
|
fmt.Printf(" %s\n", formatShortIssue(&child.Issue))
|
|
} else {
|
|
fmt.Println(formatDependencyLine("↳", child))
|
|
}
|
|
}
|
|
fmt.Println()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// showIssueAsOf displays issues as they existed at a specific commit or branch ref.
|
|
// This requires a versioned storage backend (e.g., Dolt).
|
|
func showIssueAsOf(ctx context.Context, args []string, ref string, shortMode bool) error {
|
|
var allIssues []*types.Issue
|
|
foundCount := 0
|
|
for idx, id := range args {
|
|
issue, err := store.AsOf(ctx, id, ref)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error fetching %s as of %s: %v\n", id, ref, err)
|
|
continue
|
|
}
|
|
if issue == nil {
|
|
fmt.Fprintf(os.Stderr, "Issue %s did not exist at %s\n", id, ref)
|
|
continue
|
|
}
|
|
foundCount++
|
|
|
|
if shortMode {
|
|
fmt.Println(formatShortIssue(issue))
|
|
continue
|
|
}
|
|
|
|
if jsonOutput {
|
|
allIssues = append(allIssues, issue)
|
|
continue
|
|
}
|
|
|
|
if idx > 0 {
|
|
fmt.Println("\n" + ui.RenderMuted(strings.Repeat("-", 60)))
|
|
}
|
|
|
|
// Display header with ref indicator
|
|
fmt.Printf("\n%s (as of %s)\n", formatIssueHeader(issue), ui.RenderMuted(ref))
|
|
fmt.Println(formatIssueMetadata(issue))
|
|
|
|
if issue.Description != "" {
|
|
fmt.Printf("\n%s\n%s\n", ui.RenderBold("DESCRIPTION"), uimd.RenderMarkdown(issue.Description))
|
|
}
|
|
fmt.Println()
|
|
}
|
|
|
|
if foundCount == 0 {
|
|
return showAsOfFoundNothing()
|
|
}
|
|
if jsonOutput && len(allIssues) > 0 {
|
|
return outputJSON(allIssues)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// showAsOfFoundNothing ends an --as-of read, on either route, in which no
|
|
// lookup succeeded. Each failed lookup has already said why on stderr, so this
|
|
// is plain show's ending for a batch that found nothing: the JSON error
|
|
// envelope on stdout under --json, a bare exit 1 otherwise. A batch that read
|
|
// at least one issue still exits 0, as plain show's does.
|
|
func showAsOfFoundNothing() error {
|
|
if jsonOutput {
|
|
return HandleErrorWithHintRespectJSON("no issues found matching the provided IDs",
|
|
"check the --as-of ref (a branch name, or a full 32-character commit hash from 'bd history <id>') and that each issue existed at it")
|
|
}
|
|
return SilentExit()
|
|
}
|