Skip to content

[plan] Extract validation functions from interactive forms #7218

@github-actions

Description

@github-actions

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

  1. Create pkg/cli/validators.go with exported validation functions
  2. Extract existing validation logic from interactive.go:
    • Workflow name validation (alphanumeric, hyphens, underscores)
    • Any other field validations currently inline
  3. Update the form builder to use these functions
  4. 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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions