Skip to content

feat: Add interactive CLI forms for scenario parameter collection#81

Open
tsebastiani wants to merge 4 commits intomainfrom
form
Open

feat: Add interactive CLI forms for scenario parameter collection#81
tsebastiani wants to merge 4 commits intomainfrom
form

Conversation

@tsebastiani
Copy link
Contributor

Summary

This PR introduces a new interactive CLI forms system that allows users to collect scenario parameters through guided prompts instead of CLI flags. The feature is accessible via the new --form flag in the run command.

Key Features

🎯 Interactive Parameter Collection

  • Required Fields: Always presented first, must be completed to proceed
  • Optional Fields: User can choose to set them via confirmation prompt
  • Global Values: System-wide parameters, optional via confirmation prompt
  • Smart Defaults: Support for predefined values and field defaults with [default_value]> prompting

🔍 Comprehensive Validation

  • Type Validation: String, Number, Boolean, Enum, File, FileBase64
  • Regex Validation: Custom validation patterns with custom error messages
  • Enum Support: Comma-separated or custom separator allowed values
  • File Validation: Path validation and size limits for file types
  • Recursive Validation: Default values are validated to prevent schema errors

🛡️ Security & UX

  • Secret Fields: Masked input with * for sensitive parameters
  • Error Handling: Clear validation errors with retry loops
  • Form Summary: Beautiful summary display of collected values
  • Environment Variables: Direct conversion to container environment variables

Implementation Details

New Package: pkg/forms

  • Form: Manages RequiredItems, OptionalItems, and GlobalItems arrays
  • FormPromptItem: Wraps InputField with optional predefined values
  • FormResult: Collects validated values mapped by environment variable names
  • NewForm(): Creates form with automatic field separation by Required flag

Integration with cmd/run.go

  • New --form flag enables interactive mode instead of CLI flags
  • Seamless integration with existing scenario orchestration
  • Maintains compatibility with all existing CLI flag functionality
  • Form results are converted to the same ParsedField format used by traditional flags

User Experience Flow

# Traditional CLI flags
krknctl run scenario-name --param1 value1 --param2 value2

# New interactive forms
krknctl run scenario-name --form
🔴 Required Fields
🟡 Optional Fields (with y/n confirmation)
🌐 Global Values (with y/n confirmation)
📋 Form Summary
🚀 Container execution

Testing

Comprehensive test suite with 37.1% statement coverage:

  • ✅ Form creation and field separation logic
  • ✅ All validation types and edge cases
  • ✅ Predefined values and default handling
  • ✅ Environment variable conversion
  • ✅ Error handling and malformed data
  • ✅ Memory safety and panic prevention

Backwards Compatibility

  • 100% backwards compatible - existing CLI flag usage unchanged
  • Opt-in feature - only activated with --form flag
  • Same validation logic - reuses existing InputField.Validate() methods
  • Same container interface - form results convert to standard environment variables

Future Enhancements

This forms foundation enables future features like:

  • AI-powered parameter suggestions via Lightspeed integration
  • Form templates and saved configurations
  • Interactive scenario discovery and selection
  • Enhanced validation with field dependencies

tsebastiani and others added 4 commits October 9, 2025 10:00
Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com>
- Add extensive unit tests for forms package functionality
- Test form creation, field separation, and validation logic
- Cover edge cases including malformed fields and invalid values
- Test all field types: string, number, boolean, enum, file validation
- Validate predefined values and default value handling
- Test environment variable conversion and form result operations
- 37.1% statement coverage with 100% coverage on pure functions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com>
Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant