Raz Validation
Smart options validation system for the Raz command generator.
Features
- 🎯 Context-Aware Validation - Knows which options are valid for which commands
- 🚀 Framework Support - Built-in support for Cargo, Leptos, Dioxus, and more
- 💡 Smart Suggestions - "Did you mean --release?" error messages
- 🔧 Configurable - Multiple validation levels from strict to permissive
- 🧩 Extensible - Easy to add new frameworks and custom options
Quick Start
use ;
// Create validation engine
let engine = new;
// Validate cargo options
assert!;
assert!;
// Validate leptos options
assert!;
// Get suggestions for typos
let suggestions = engine.suggest_option;
assert!;
Validation Levels
- Off - No validation (pass everything through)
- Normal - Validate known options, allow unknown ones
- Strict - Reject unknown options with helpful error messages
let config = with_level;
let engine = with_config;
// This will fail in strict mode
let result = engine.validate_option;
assert!;
Supported Frameworks
Cargo
- Core cargo commands:
build,test,run,check,clippy - Common options:
--release,--features,--target,--jobs - Conflict detection:
--libvs--binvs--bins
Leptos
- Commands:
leptos build,leptos serve,leptos watch - Framework options:
--bin-features,--lib-features,--hot-reload - Template support:
leptos new --template start-axum
Integration with Override Parser
The validation system integrates seamlessly with the raz-override parser:
use OverrideParser;
use ;
// Create parser with validation
let config = with_level;
let parser = with_validation_config;
// Parse and validate
let parsed = parser.parse.unwrap;
parser.validate.unwrap; // Will validate using the engine
// Get suggestions for typos
let suggestions = parser.suggest_option;
Adding Custom Providers
use ;
;
// Register the provider
let mut engine = new;
engine.register_provider;
Error Handling
The validation system provides detailed error messages:
match engine.validate_option
Performance
- Lazy loading of option definitions
- Efficient fuzzy matching for suggestions
- Minimal overhead in permissive modes
- Caching of parsed help output (future feature)
Examples
See examples/basic_validation.rs for a comprehensive demo: