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.go with 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
AI generated by Plan Command for discussion #7214
Objective
Extract inline validation logic into separate, testable functions in a new
pkg/cli/validators.gofile.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
pkg/cli/validators.gowith exported validation functionsinteractive.go:pkg/cli/validators_test.goExample structure:
Files to Create
pkg/cli/validators.go- Validation functionspkg/cli/validators_test.go- Unit testsFiles to Modify
pkg/cli/interactive.go- Use extracted validation functionsAcceptance Criteria
Related to [plan] Enhance interactive workflow builder with huh v0.7.0+ features #7216