( maybe_config: Result<Config, AppError>, maybe_name: Option<String>, url: &str, after_workon: Option<String>, after_clone: Option<String>, override_path: Option<String>, tags: Option<BTreeSet<
| 8 | use yansi::Paint; |
| 9 | |
| 10 | pub fn add_entry( |
| 11 | maybe_config: Result<Config, AppError>, |
| 12 | maybe_name: Option<String>, |
| 13 | url: &str, |
| 14 | after_workon: Option<String>, |
| 15 | after_clone: Option<String>, |
| 16 | override_path: Option<String>, |
| 17 | tags: Option<BTreeSet<String>>, |
| 18 | trusted: bool, |
| 19 | ) -> Result<(), AppError> { |
| 20 | let name = maybe_name |
| 21 | .ok_or_else(|| AppError::UserError(format!("No project name specified for {}", url))) |
| 22 | .or_else(|_| repo_name_from_url(url).map(ToOwned::to_owned))?; |
| 23 | let config: Config = maybe_config?; |
| 24 | if config.projects.contains_key(&name) { |
| 25 | Err(AppError::UserError(format!( |
| 26 | "Project key {} already exists, not gonna overwrite it for you", |
| 27 | name |
| 28 | ))) |
| 29 | } else { |
| 30 | let default_after_clone = config.settings.default_after_clone.clone(); |
| 31 | let default_after_workon = config.settings.default_after_workon.clone(); |
| 32 | |
| 33 | let project_tags: Option<BTreeSet<String>> = if tags.is_some() && config.settings.default_tags.is_some() { |
| 34 | tags.zip(config.settings.default_tags).map(|(t1, t2)| t1.union(&t2).cloned().collect()) |
| 35 | } else { |
| 36 | tags.or(config.settings.default_tags) |
| 37 | }; |
| 38 | |
| 39 | config::write_project(&Project { |
| 40 | git: url.to_owned(), |
| 41 | name, |
| 42 | after_clone: after_clone.or(default_after_clone), |
| 43 | after_workon: after_workon.or(default_after_workon), |
| 44 | override_path, |
| 45 | tags: project_tags, |
| 46 | bare: None, |
| 47 | additional_remotes: None, |
| 48 | trusted, |
| 49 | project_config_path: "default".to_string(), |
| 50 | })?; |
| 51 | Ok(()) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | pub fn remove_project(maybe_config: Result<Config, AppError>, project_name: &str, purge_directory: bool) -> Result<(), AppError> { |
| 56 | let config: Config = maybe_config?; |
no test coverage detected