You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[plan] Extract validation functions from interactive forms #7218
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.gopackage cli
import (
"errors""regexp"
)
varworkflowNameRegex=regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
funcValidateWorkflowName(sstring) error {
ifs=="" {
returnerrors.New("workflow name cannot be empty")
}
if!workflowNameRegex.MatchString(s) {
returnerrors.New("workflow name must contain only alphanumeric characters, hyphens, and underscores")
}
returnnil
}
// Then in interactive.go:huh.NewInput().
Title("Workflow Name").
Value(&name).
Validate(ValidateWorkflowName)
Activity