Refactor: Extract duplicated validation logic to internal/validation
Extracted repeated priority and ID validation patterns from CLI commands into reusable functions in internal/validation/bead.go. Changes: - Added ValidatePriority(): Combines parsing and error handling - Added ValidateIDFormat(): Validates ID format and extracts prefix - Added ValidatePrefix(): Validates prefix matching with database config - Updated create.go and show.go to use new validation functions - Simplified force flag logic to always call ValidatePrefix() - Added comprehensive tests for all validation functions - Added TODO comment for daemon mode validation enhancement Results: - Reduced code duplication by ~20 lines - Centralized validation logic for easier maintenance - Consistent error messages across all commands - All tests passing Fixes bd-g5p7 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -345,9 +345,9 @@ var updateCmd = &cobra.Command{
|
||||
}
|
||||
if cmd.Flags().Changed("priority") {
|
||||
priorityStr, _ := cmd.Flags().GetString("priority")
|
||||
priority := validation.ParsePriority(priorityStr)
|
||||
if priority == -1 {
|
||||
fmt.Fprintf(os.Stderr, "Error: invalid priority %q (expected 0-4 or P0-P4)\n", priorityStr)
|
||||
priority, err := validation.ValidatePriority(priorityStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
updates["priority"] = priority
|
||||
|
||||
Reference in New Issue
Block a user