bd sync: 2025-11-05 13:56:12

This commit is contained in:
Steve Yegge
2025-11-05 13:56:12 -08:00
parent 187c395e3e
commit 3973ccbfa3
5 changed files with 81 additions and 4 deletions

View File

@@ -82,7 +82,14 @@ var createCmd = &cobra.Command{
if acceptance == "" && tmpl != nil {
acceptance = tmpl.AcceptanceCriteria
}
priority, _ := cmd.Flags().GetInt("priority")
// Parse priority (supports both "1" and "P1" formats)
priorityStr, _ := cmd.Flags().GetString("priority")
priority := parsePriority(priorityStr)
if priority == -1 {
fmt.Fprintf(os.Stderr, "Error: invalid priority %q (expected 0-4 or P0-P4)\n", priorityStr)
os.Exit(1)
}
if cmd.Flags().Changed("priority") == false && tmpl != nil {
priority = tmpl.Priority
}
@@ -375,7 +382,7 @@ func init() {
createCmd.Flags().StringP("description", "d", "", "Issue description")
createCmd.Flags().String("design", "", "Design notes")
createCmd.Flags().String("acceptance", "", "Acceptance criteria")
createCmd.Flags().IntP("priority", "p", 2, "Priority (0-4, 0=highest)")
createCmd.Flags().StringP("priority", "p", "2", "Priority (0-4 or P0-P4, 0=highest)")
createCmd.Flags().StringP("type", "t", "task", "Issue type (bug|feature|task|epic|chore)")
createCmd.Flags().StringP("assignee", "a", "", "Assignee")
createCmd.Flags().StringSliceP("labels", "l", []string{}, "Labels (comma-separated)")

View File

@@ -40,8 +40,16 @@ type IssueTemplate struct {
}
// parsePriority extracts and validates a priority value from content.
// Supports both numeric (0-4) and P-prefix format (P0-P4).
// Returns the parsed priority (0-4) or -1 if invalid.
func parsePriority(content string) int {
content = strings.TrimSpace(content)
// Handle "P1", "P0", etc. format
if strings.HasPrefix(strings.ToUpper(content), "P") {
content = content[1:] // Strip the "P" prefix
}
var p int
if _, err := fmt.Sscanf(content, "%d", &p); err == nil && p >= 0 && p <= 4 {
return p

52
cmd/bd/priority_test.go Normal file
View File

@@ -0,0 +1,52 @@
package main
import (
"testing"
)
func TestParsePriority(t *testing.T) {
tests := []struct {
input string
expected int
}{
// Numeric format
{"0", 0},
{"1", 1},
{"2", 2},
{"3", 3},
{"4", 4},
// P-prefix format (uppercase)
{"P0", 0},
{"P1", 1},
{"P2", 2},
{"P3", 3},
{"P4", 4},
// P-prefix format (lowercase)
{"p0", 0},
{"p1", 1},
{"p2", 2},
// With whitespace
{" 1 ", 1},
{" P1 ", 1},
// Invalid cases (returns -1)
{"5", -1}, // Out of range
{"-1", -1}, // Negative
{"P5", -1}, // Out of range with prefix
{"abc", -1}, // Not a number
{"P", -1}, // Just the prefix
{"PP1", -1}, // Double prefix
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := parsePriority(tt.input)
if got != tt.expected {
t.Errorf("parsePriority(%q) = %d, want %d", tt.input, got, tt.expected)
}
})
}
}

View File

@@ -372,7 +372,12 @@ var updateCmd = &cobra.Command{
updates["status"] = status
}
if cmd.Flags().Changed("priority") {
priority, _ := cmd.Flags().GetInt("priority")
priorityStr, _ := cmd.Flags().GetString("priority")
priority := parsePriority(priorityStr)
if priority == -1 {
fmt.Fprintf(os.Stderr, "Error: invalid priority %q (expected 0-4 or P0-P4)\n", priorityStr)
os.Exit(1)
}
updates["priority"] = priority
}
if cmd.Flags().Changed("title") {
@@ -781,7 +786,7 @@ var closeCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(showCmd)
updateCmd.Flags().StringP("status", "s", "", "New status")
updateCmd.Flags().IntP("priority", "p", 0, "New priority")
updateCmd.Flags().StringP("priority", "p", "", "New priority (0-4 or P0-P4)")
updateCmd.Flags().String("title", "", "New title")
updateCmd.Flags().StringP("assignee", "a", "", "New assignee")
updateCmd.Flags().StringP("description", "d", "", "Issue description")