Add substring ID matching for all bd commands

- Enhanced ResolvePartialID to handle:
  - Bare hashes: 07b8c8 → bd-07b8c8
  - Prefix without hyphen: bd07b8c8 → bd-07b8c8
  - Full IDs: bd-07b8c8 (unchanged)
  - Substring matching: 07b → finds bd-07b8c8

- Added RPC support:
  - New OpResolveID operation
  - handleResolveID server handler
  - ResolveID client method

- Updated all commands to resolve IDs:
  - show, update, close, reopen
  - dep (add, remove, tree)
  - label (add, remove, list)

- Works in both daemon and direct modes

Fixes bd-0591c3
This commit is contained in:
Steve Yegge
2025-10-30 19:20:50 -07:00
parent 185c734d75
commit 11c26d5af8
10 changed files with 343 additions and 124 deletions

View File

@@ -26,11 +26,46 @@ var depAddCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
depType, _ := cmd.Flags().GetString("type")
ctx := context.Background()
// Resolve partial IDs first
var fromID, toID string
if daemonClient != nil {
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fromID = string(resp.Data)
resolveArgs = &rpc.ResolveIDArgs{ID: args[1]}
resp, err = daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
toID = string(resp.Data)
} else {
var err error
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
toID, err = utils.ResolvePartialID(ctx, store, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
}
// If daemon is running, use RPC
if daemonClient != nil {
depArgs := &rpc.DepAddArgs{
FromID: args[0],
ToID: args[1],
FromID: fromID,
ToID: toID,
DepType: depType,
}
@@ -52,23 +87,9 @@ var depAddCmd = &cobra.Command{
}
// Direct mode
ctx := context.Background()
fullFromID, err := utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fullToID, err := utils.ResolvePartialID(ctx, store, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
dep := &types.Dependency{
IssueID: fullFromID,
DependsOnID: fullToID,
IssueID: fromID,
DependsOnID: toID,
Type: types.DependencyType(depType),
}
@@ -108,8 +129,8 @@ var depAddCmd = &cobra.Command{
if jsonOutput {
outputJSON(map[string]interface{}{
"status": "added",
"issue_id": fullFromID,
"depends_on_id": fullToID,
"issue_id": fromID,
"depends_on_id": toID,
"type": depType,
})
return
@@ -117,7 +138,7 @@ var depAddCmd = &cobra.Command{
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("%s Added dependency: %s depends on %s (%s)\n",
green("✓"), fullFromID, fullToID, depType)
green("✓"), fromID, toID, depType)
},
}
@@ -126,11 +147,46 @@ var depRemoveCmd = &cobra.Command{
Short: "Remove a dependency",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
// Resolve partial IDs first
var fromID, toID string
if daemonClient != nil {
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fromID = string(resp.Data)
resolveArgs = &rpc.ResolveIDArgs{ID: args[1]}
resp, err = daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
toID = string(resp.Data)
} else {
var err error
fromID, err = utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
toID, err = utils.ResolvePartialID(ctx, store, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
}
// If daemon is running, use RPC
if daemonClient != nil {
depArgs := &rpc.DepRemoveArgs{
FromID: args[0],
ToID: args[1],
FromID: fromID,
ToID: toID,
}
resp, err := daemonClient.RemoveDependency(depArgs)
@@ -146,24 +202,13 @@ var depRemoveCmd = &cobra.Command{
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("%s Removed dependency: %s no longer depends on %s\n",
green("✓"), args[0], args[1])
green("✓"), fromID, toID)
return
}
// Direct mode
ctx := context.Background()
fullFromID, err := utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fullToID, err := utils.ResolvePartialID(ctx, store, args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving dependency ID %s: %v\n", args[1], err)
os.Exit(1)
}
fullFromID := fromID
fullToID := toID
if err := store.RemoveDependency(ctx, fullFromID, fullToID, actor); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
@@ -193,6 +238,27 @@ var depTreeCmd = &cobra.Command{
Short: "Show dependency tree",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
// Resolve partial ID first
var fullID string
if daemonClient != nil {
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
fullID = string(resp.Data)
} else {
var err error
fullID, err = utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", args[0], err)
os.Exit(1)
}
}
// If daemon is running but doesn't support this command, use direct storage
if daemonClient != nil && store == nil {
var err error
@@ -212,14 +278,6 @@ var depTreeCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Error: --max-depth must be >= 1\n")
os.Exit(1)
}
ctx := context.Background()
fullID, err := utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", args[0], err)
os.Exit(1)
}
tree, err := store.GetDependencyTree(ctx, fullID, maxDepth, showAllPaths, reverse)
if err != nil {

View File

@@ -81,20 +81,31 @@ var labelAddCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
issueIDs, label := parseLabelArgs(args)
// Resolve partial IDs if in direct mode
if daemonClient == nil {
ctx := context.Background()
resolvedIDs := make([]string, 0, len(issueIDs))
for _, id := range issueIDs {
fullID, err := utils.ResolvePartialID(ctx, store, id)
// Resolve partial IDs
ctx := context.Background()
resolvedIDs := make([]string, 0, len(issueIDs))
for _, id := range issueIDs {
var fullID string
var err error
if daemonClient != nil {
resolveArgs := &rpc.ResolveIDArgs{ID: id}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
fullID = string(resp.Data)
} else {
fullID, err = utils.ResolvePartialID(ctx, store, id)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
resolvedIDs = append(resolvedIDs, fullID)
}
issueIDs = resolvedIDs
resolvedIDs = append(resolvedIDs, fullID)
}
issueIDs = resolvedIDs
processBatchLabelOperation(issueIDs, label, "added",
func(issueID, lbl string) error {
@@ -115,20 +126,31 @@ var labelRemoveCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
issueIDs, label := parseLabelArgs(args)
// Resolve partial IDs if in direct mode
if daemonClient == nil {
ctx := context.Background()
resolvedIDs := make([]string, 0, len(issueIDs))
for _, id := range issueIDs {
fullID, err := utils.ResolvePartialID(ctx, store, id)
// Resolve partial IDs
ctx := context.Background()
resolvedIDs := make([]string, 0, len(issueIDs))
for _, id := range issueIDs {
var fullID string
var err error
if daemonClient != nil {
resolveArgs := &rpc.ResolveIDArgs{ID: id}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
fullID = string(resp.Data)
} else {
fullID, err = utils.ResolvePartialID(ctx, store, id)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
resolvedIDs = append(resolvedIDs, fullID)
}
issueIDs = resolvedIDs
resolvedIDs = append(resolvedIDs, fullID)
}
issueIDs = resolvedIDs
processBatchLabelOperation(issueIDs, label, "removed",
func(issueID, lbl string) error {
@@ -146,21 +168,29 @@ var labelListCmd = &cobra.Command{
Short: "List labels for an issue",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
issueID := args[0]
ctx := context.Background()
var labels []string
// Resolve partial ID if in direct mode
if daemonClient == nil {
fullID, err := utils.ResolvePartialID(ctx, store, issueID)
// Resolve partial ID first
var issueID string
if daemonClient != nil {
resolveArgs := &rpc.ResolveIDArgs{ID: args[0]}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", issueID, err)
fmt.Fprintf(os.Stderr, "Error resolving issue ID %s: %v\n", args[0], err)
os.Exit(1)
}
issueID = string(resp.Data)
} else {
var err error
issueID, err = utils.ResolvePartialID(ctx, store, args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", args[0], err)
os.Exit(1)
}
issueID = fullID
}
var labels []string
// Use daemon if available
if daemonClient != nil {
resp, err := daemonClient.Show(&rpc.ShowArgs{ID: issueID})

View File

@@ -24,11 +24,33 @@ This is more explicit than 'bd update --status open' and emits a Reopened event.
reason, _ := cmd.Flags().GetString("reason")
ctx := context.Background()
// Resolve partial IDs first
var resolvedIDs []string
if daemonClient != nil {
for _, id := range args {
resolveArgs := &rpc.ResolveIDArgs{ID: id}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
}
} else {
var err error
resolvedIDs, err = utils.ResolvePartialIDs(ctx, store, args)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
reopenedIssues := []*types.Issue{}
// If daemon is running, use RPC
if daemonClient != nil {
for _, id := range args {
for _, id := range resolvedIDs {
openStatus := string(types.StatusOpen)
updateArgs := &rpc.UpdateArgs{
ID: id,

View File

@@ -20,10 +20,35 @@ var showCmd = &cobra.Command{
Short: "Show issue details",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
// Resolve partial IDs first
var resolvedIDs []string
if daemonClient != nil {
// In daemon mode, resolve via RPC
for _, id := range args {
resolveArgs := &rpc.ResolveIDArgs{ID: id}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
}
} else {
// In direct mode, resolve via storage
var err error
resolvedIDs, err = utils.ResolvePartialIDs(ctx, store, args)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
// If daemon is running, use RPC
if daemonClient != nil {
allDetails := []interface{}{}
for idx, id := range args {
for idx, id := range resolvedIDs {
showArgs := &rpc.ShowArgs{ID: id}
resp, err := daemonClient.Show(showArgs)
if err != nil {
@@ -158,22 +183,15 @@ var showCmd = &cobra.Command{
}
// Direct mode
ctx := context.Background()
allDetails := []interface{}{}
for idx, id := range args {
fullID, err := utils.ResolvePartialID(ctx, store, id)
for idx, id := range resolvedIDs {
issue, err := store.GetIssue(ctx, id)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
issue, err := store.GetIssue(ctx, fullID)
if err != nil {
fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", fullID, err)
fmt.Fprintf(os.Stderr, "Error fetching %s: %v\n", id, err)
continue
}
if issue == nil {
fmt.Fprintf(os.Stderr, "Issue %s not found\n", fullID)
fmt.Fprintf(os.Stderr, "Issue %s not found\n", id)
continue
}
@@ -360,10 +378,33 @@ var updateCmd = &cobra.Command{
return
}
ctx := context.Background()
// Resolve partial IDs first
var resolvedIDs []string
if daemonClient != nil {
for _, id := range args {
resolveArgs := &rpc.ResolveIDArgs{ID: id}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
}
} else {
var err error
resolvedIDs, err = utils.ResolvePartialIDs(ctx, store, args)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
// If daemon is running, use RPC
if daemonClient != nil {
updatedIssues := []*types.Issue{}
for _, id := range args {
for _, id := range resolvedIDs {
updateArgs := &rpc.UpdateArgs{ID: id}
// Map updates to RPC args
@@ -416,28 +457,21 @@ var updateCmd = &cobra.Command{
}
// Direct mode
ctx := context.Background()
updatedIssues := []*types.Issue{}
for _, id := range args {
fullID, err := utils.ResolvePartialID(ctx, store, id)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
if err := store.UpdateIssue(ctx, fullID, updates, actor); err != nil {
fmt.Fprintf(os.Stderr, "Error updating %s: %v\n", fullID, err)
continue
}
for _, id := range resolvedIDs {
if err := store.UpdateIssue(ctx, id, updates, actor); err != nil {
fmt.Fprintf(os.Stderr, "Error updating %s: %v\n", id, err)
continue
}
if jsonOutput {
issue, _ := store.GetIssue(ctx, fullID)
if jsonOutput {
issue, _ := store.GetIssue(ctx, id)
if issue != nil {
updatedIssues = append(updatedIssues, issue)
}
} else {
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("%s Updated issue: %s\n", green("✓"), fullID)
fmt.Printf("%s Updated issue: %s\n", green("✓"), id)
}
}
@@ -658,10 +692,33 @@ var closeCmd = &cobra.Command{
reason = "Closed"
}
ctx := context.Background()
// Resolve partial IDs first
var resolvedIDs []string
if daemonClient != nil {
for _, id := range args {
resolveArgs := &rpc.ResolveIDArgs{ID: id}
resp, err := daemonClient.ResolveID(resolveArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving ID %s: %v\n", id, err)
os.Exit(1)
}
resolvedIDs = append(resolvedIDs, string(resp.Data))
}
} else {
var err error
resolvedIDs, err = utils.ResolvePartialIDs(ctx, store, args)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
// If daemon is running, use RPC
if daemonClient != nil {
closedIssues := []*types.Issue{}
for _, id := range args {
for _, id := range resolvedIDs {
closeArgs := &rpc.CloseArgs{
ID: id,
Reason: reason,
@@ -690,27 +747,20 @@ var closeCmd = &cobra.Command{
}
// Direct mode
ctx := context.Background()
closedIssues := []*types.Issue{}
for _, id := range args {
fullID, err := utils.ResolvePartialID(ctx, store, id)
if err != nil {
fmt.Fprintf(os.Stderr, "Error resolving %s: %v\n", id, err)
continue
}
if err := store.CloseIssue(ctx, fullID, reason, actor); err != nil {
fmt.Fprintf(os.Stderr, "Error closing %s: %v\n", fullID, err)
for _, id := range resolvedIDs {
if err := store.CloseIssue(ctx, id, reason, actor); err != nil {
fmt.Fprintf(os.Stderr, "Error closing %s: %v\n", id, err)
continue
}
if jsonOutput {
issue, _ := store.GetIssue(ctx, fullID)
issue, _ := store.GetIssue(ctx, id)
if issue != nil {
closedIssues = append(closedIssues, issue)
}
} else {
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("%s Closed %s: %s\n", green("✓"), fullID, reason)
fmt.Printf("%s Closed %s: %s\n", green("✓"), id, reason)
}
}