(maybe_config: Result<Config, AppError>, name: &str, remote_name: String, git: String)
| 72 | } |
| 73 | |
| 74 | pub fn add_remote(maybe_config: Result<Config, AppError>, name: &str, remote_name: String, git: String) -> Result<(), AppError> { |
| 75 | let config: Config = maybe_config?; |
| 76 | if !config.projects.contains_key(name) { |
| 77 | return Err(AppError::UserError(format!("Project key {} does not exists. Can not update.", name))); |
| 78 | } |
| 79 | let mut project_config: Project = config.projects.get(name).expect("Already checked in the if above").clone(); |
| 80 | let mut additional_remotes = project_config.additional_remotes.unwrap_or_default(); |
| 81 | if additional_remotes.iter().any(|r| r.name == remote_name) { |
| 82 | return Err(AppError::UserError(format!( |
| 83 | "Remote {} for project {} does already exist. Can not add.", |
| 84 | remote_name, name |
| 85 | ))); |
| 86 | } |
| 87 | additional_remotes.push(Remote { name: remote_name, git }); |
| 88 | project_config.additional_remotes = Some(additional_remotes); |
| 89 | |
| 90 | config::write_project(&project_config)?; |
| 91 | Ok(()) |
| 92 | } |
| 93 | |
| 94 | pub fn remove_remote(maybe_config: Result<Config, AppError>, name: &str, remote_name: String) -> Result<(), AppError> { |
| 95 | let config: Config = maybe_config?; |
no test coverage detected