-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
Description
Objective
Extract inline validation logic into separate, testable functions in a new pkg/cli/validators.go file.
Context
Currently, validation logic is defined inline within the form builder, making it difficult to test, reuse, and maintain. Extracting these into dedicated functions improves code quality and enables unit testing.
Approach
- Create
pkg/cli/validators.gowith exported validation functions - Extract existing validation logic from
interactive.go:- Workflow name validation (alphanumeric, hyphens, underscores)
- Any other field validations currently inline
- Update the form builder to use these functions
- Add unit tests in
pkg/cli/validators_test.go
Example structure:
// pkg/cli/validators.go
package cli
import (
"errors"
"regexp"
)
var workflowNameRegex = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
func ValidateWorkflowName(s string) error {
if s == "" {
return errors.New("workflow name cannot be empty")
}
if !workflowNameRegex.MatchString(s) {
return errors.New("workflow name must contain only alphanumeric characters, hyphens, and underscores")
}
return nil
}
// Then in interactive.go:
huh.NewInput().
Title("Workflow Name").
Value(&name).
Validate(ValidateWorkflowName)Files to Create
- Create:
pkg/cli/validators.go- Validation functions - Create:
pkg/cli/validators_test.go- Unit tests
Files to Modify
- Update:
pkg/cli/interactive.go- Use extracted validation functions
Acceptance Criteria
- All validation logic is extracted to separate functions
- Validation functions are pure and testable
- Unit tests cover valid and invalid cases
- Existing form behavior is unchanged
- Code is more maintainable and reusable
Related to [plan] Enhance interactive workflow builder with huh v0.7.0+ features #7216
AI generated by Plan Command for discussion #7214