1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//! # FSValidator
//!
//! A library for validating filesystem structures against a declarative schema.
//!
//! This crate allows you to define expected file and directory structures and validate
//! that real filesystem paths match those expectations. It's useful for ensuring project layouts,
//! validating data directories, or enforcing configuration structures.
//!
//! ## Features
//!
//! - Validate files and directories using literal names or regex patterns
//! - Support for complex nested directory structures
//! - Template system for reusing common structures
//! - Control validation strictness with required flags and restricted directories
//! - Load definitions from TOML or JSON files
//! - Comprehensive validation with categorized errors for programmatic usage
//! - Colorful, symbolic display for human-readable output
//! - Fluent builder API for programmatically constructing validation models
//!
//! # Examples
//!
//! ## Using TOML Config File
//!
//! ```rust,no_run
//! # #[cfg(feature = "toml")]
//! # fn main() -> anyhow::Result<()> {
//! use anyhow::Result;
//! use fsvalidator::from_toml;
//! use fsvalidator::display::format_validation_result;
//!
//! // Load structure definition from TOML
//! let root = from_toml("path/to/fsvalidator.toml")?;
//!
//! // Validate a directory against the defined structure
//! // Note: The path should be the direct path to the item being validated
//! let path = "./path/to/validate";
//!
//! // Validate and get comprehensive results (with categorized errors)
//! let validation_result = root.validate(path);
//!
//! // Display results with colorful, symbolic output
//! println!("{}", format_validation_result(&validation_result, path));
//!
//! // Check success/failure and handle accordingly
//! if validation_result.is_err() {
//! eprintln!("Validation failed!");
//! }
//!
//! Ok(())
//! # }
//! # #[cfg(not(feature = "toml"))]
//! # fn main() {}
//! ```
//!
//! ## Using Builder API
//!
//! ```rust,no_run
//! use anyhow::Result;
//! use fsvalidator::ModelBuilder;
//! use fsvalidator::display::format_validation_result;
//!
//! fn main() -> Result<()> {
//! // Create a project structure using the builder API
//! let project = ModelBuilder::new_dir("project")
//! .required(true)
//! .allow_defined_only(true)
//! .add_file("README.md", true)
//! .add_dir("src", true)
//! .add_file_pattern(".*\\.rs", true)
//! .up()
//! .add_dir("tests", false)
//! .add_file_pattern("test_.*\\.rs", false)
//! .build();
//!
//! // Validate a directory against the defined structure
//! let path = "./path/to/validate";
//! let validation_result = project.validate(path);
//!
//! // Display results with colorful, symbolic output
//! println!("{}", format_validation_result(&validation_result, path));
//!
//! Ok(())
//! }
//! ```
//!
//! ## Schema Definition
//!
//! The schema can be defined in TOML or JSON, with a structure like this:
//!
//! ```toml
//! [root]
//! type = "dir"
//! name = "project"
//! required = true
//!
//! [[root.children]]
//! type = "file"
//! name = "README.md"
//! required = true
//!
//! [[root.children]]
//! type = "dir"
//! name = "src"
//! required = true
//!
//! [[root.children.children]]
//! type = "file"
//! pattern = ".*\.rs"
//! required = true
//! ```
// Re-export validation error types
pub use ;
// Re-export model builder for easier access
pub use ModelBuilder;
/// Load a filesystem structure definition from a TOML file and convert it to a validation model.
///
/// # Arguments
///
/// * `structure_def_path` - Path to the TOML file containing the structure definition
///
/// # Returns
///
/// * `Result<model::Node>` - The root node of the validation model
///
/// # Example
///
/// ```rust,no_run
/// use anyhow::Result;
/// use fsvalidator::from_toml;
/// use fsvalidator::display::format_validation_result;
///
/// fn main() -> Result<()> {
/// let root = from_toml("path/to/structure.toml")?;
///
/// // Validate and get comprehensive results
/// let path = "./path/to/validate";
/// let result = root.validate(path);
/// println!("{}", format_validation_result(&result, path));
///
/// // Check if validation passed
/// if result.is_ok() {
/// println!("Validation passed!");
/// }
/// Ok(())
/// }
/// ```
/// Load a filesystem structure definition from a JSON file and convert it to a validation model.
///
/// # Arguments
///
/// * `structure_def_path` - Path to the JSON file containing the structure definition
///
/// # Returns
///
/// * `Result<model::Node>` - The root node of the validation model
///
/// # Example
///
/// ```rust,no_run
/// use anyhow::Result;
/// use fsvalidator::from_json;
/// use fsvalidator::display::format_validation_result;
///
/// fn main() -> Result<()> {
/// let root = from_json("path/to/structure.json")?;
///
/// // Validate and get comprehensive results
/// let path = "./path/to/validate";
/// let result = root.validate(path);
/// println!("{}", format_validation_result(&result, path));
///
/// // Check if validation passed
/// if result.is_ok() {
/// println!("Validation passed!");
/// }
/// Ok(())
/// }
/// ```