Add paths to the context configuration. # Arguments `paths` - List of paths to add `force` - If true, skip validation that the path exists # Returns A Result indicating success or an error
(&mut self, os: &Os, paths: Vec<String>, force: bool)
| 130 | /// # Returns |
| 131 | /// A Result indicating success or an error |
| 132 | pub async fn add_paths(&mut self, os: &Os, paths: Vec<String>, force: bool) -> Result<()> { |
| 133 | // Validate paths exist before adding them |
| 134 | if !force { |
| 135 | let mut context_files = Vec::new(); |
| 136 | |
| 137 | // Check each path to make sure it exists or matches at least one file |
| 138 | for path in &paths { |
| 139 | // We're using a temporary context_files vector just for validation |
| 140 | // Pass is_validation=true to ensure we error if glob patterns don't match any files |
| 141 | match process_path(os, path, &mut context_files, true).await { |
| 142 | Ok(_) => {}, // Path is valid |
| 143 | Err(e) => return Err(eyre!("Invalid path '{}': {}. Use --force to add anyway.", path, e)), |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | for path in paths { |
| 149 | if self.paths.iter().any(|p| p == path.as_str()) { |
| 150 | return Err(eyre!("Rule '{}' already exists.", path)); |
| 151 | } |
| 152 | |
| 153 | // The assumption here is that we are only calling [add_paths] for adding paths in |
| 154 | // session |
| 155 | self.paths.push(ContextFilePath::Session(path)); |
| 156 | } |
| 157 | |
| 158 | Ok(()) |
| 159 | } |
| 160 | |
| 161 | /// Remove paths from the context configuration. |
| 162 | /// |