1pub mod error;
8pub mod provider;
9pub mod registry;
10pub mod suggestion;
11pub mod validation;
12
13pub use error::{ValidationError, ValidationResult};
14pub use provider::{OptionDef, OptionProvider, OptionValueType, ValueValidator};
15pub use registry::ValidationRegistry;
16pub use validation::{ValidationConfig, ValidationLevel};
17
18use std::collections::HashMap;
19
20pub struct ValidationEngine {
22 registry: ValidationRegistry,
23 config: ValidationConfig,
24}
25
26impl Default for ValidationEngine {
27 fn default() -> Self {
28 Self::new()
29 }
30}
31
32impl ValidationEngine {
33 pub fn new() -> Self {
35 let mut registry = ValidationRegistry::new();
36
37 registry.register_provider(Box::new(provider::cargo::CargoProvider::new()));
39
40 Self {
41 registry,
42 config: ValidationConfig::default(),
43 }
44 }
45
46 pub fn with_config(config: ValidationConfig) -> Self {
48 let mut engine = Self::new();
49 engine.config = config;
50 engine
51 }
52
53 pub fn validate_option(
55 &self,
56 command: &str,
57 option: &str,
58 value: Option<&str>,
59 ) -> ValidationResult<()> {
60 if self.config.level == ValidationLevel::Off {
61 return Ok(());
62 }
63
64 self.registry
65 .validate_option(command, option, value, &self.config)
66 }
67
68 pub fn validate_options(
70 &self,
71 command: &str,
72 options: &HashMap<String, Option<String>>,
73 ) -> ValidationResult<()> {
74 for (option, value) in options {
75 self.validate_option(command, option, value.as_deref())?;
76 }
77 Ok(())
78 }
79
80 pub fn suggest_option(&self, command: &str, option: &str) -> Vec<String> {
82 self.registry.suggest_option(command, option)
83 }
84
85 pub fn get_options(&self, command: &str) -> Vec<OptionDef> {
87 self.registry.get_options(command)
88 }
89
90 pub fn register_provider(&mut self, provider: Box<dyn OptionProvider>) {
92 self.registry.register_provider(provider);
93 }
94}