(maybe_config: Result<Config, AppError>, cmd: &str, tag_name: &str, parallel_raw: &Option<String>)
| 145 | } |
| 146 | |
| 147 | pub fn autotag(maybe_config: Result<Config, AppError>, cmd: &str, tag_name: &str, parallel_raw: &Option<String>) -> Result<(), AppError> { |
| 148 | let config = maybe_config?; |
| 149 | |
| 150 | let tags: BTreeMap<String, Tag> = config.settings.tags.clone().unwrap_or_default(); |
| 151 | if tags.contains_key(tag_name) { |
| 152 | init_threads(parallel_raw)?; |
| 153 | |
| 154 | let projects: Vec<&Project> = config.projects.values().collect(); |
| 155 | |
| 156 | let script_results = projects |
| 157 | .par_iter() |
| 158 | .map(|p| { |
| 159 | let shell = config.settings.get_shell_or_default(); |
| 160 | let path = &config.actual_path_to_project(p); |
| 161 | spawn_maybe(&shell, cmd, path, &p.name, random_color()) |
| 162 | }) |
| 163 | .collect::<Vec<Result<(), AppError>>>(); |
| 164 | |
| 165 | // map with projects and filter if result == 0 |
| 166 | let filtered_projects: Vec<&Project> = script_results |
| 167 | .into_iter() |
| 168 | .zip(projects) |
| 169 | .filter(|(x, _)| x.is_ok()) |
| 170 | .map(|(_, p)| p) |
| 171 | .collect::<Vec<&Project>>(); |
| 172 | |
| 173 | for project in filtered_projects.iter() { |
| 174 | add_tag(&config, project.name.clone(), tag_name.to_string())?; |
| 175 | } |
| 176 | Ok(()) |
| 177 | } else { |
| 178 | Err(AppError::UserError(format!("Unknown tag {}", tag_name))) |
| 179 | } |
| 180 | } |
no test coverage detected