(mut config: Config, args: &ArgMatches)
| 303 | } |
| 304 | |
| 305 | pub async fn exec_edit(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { |
| 306 | let server = args.get_one::<String>("server").unwrap().as_str(); |
| 307 | |
| 308 | let old_url = config.get_host_url(Some(server))?; |
| 309 | |
| 310 | let new_nick = args.get_one::<String>("nickname").map(|s| s.as_str()); |
| 311 | let new_url = args.get_one::<String>("url").map(|s| s.as_str()); |
| 312 | let (new_host, new_proto) = match new_url { |
| 313 | None => (None, None), |
| 314 | Some(new_url) => { |
| 315 | let (new_host, new_proto) = host_or_url_to_host_and_protocol(new_url); |
| 316 | let new_proto = new_proto.ok_or_else(|| anyhow::anyhow!("Invalid url: {new_url}"))?; |
| 317 | (Some(new_host), Some(new_proto)) |
| 318 | } |
| 319 | }; |
| 320 | |
| 321 | let no_fingerprint = args.get_flag("no-fingerprint"); |
| 322 | let force = args.get_flag("force"); |
| 323 | |
| 324 | if let Some(new_proto) = new_proto { |
| 325 | valid_protocol_or_error(new_proto)?; |
| 326 | } |
| 327 | |
| 328 | let (old_nick, old_host, old_proto) = config.edit_server(server, new_nick, new_host, new_proto)?; |
| 329 | let server = new_nick.unwrap_or(server); |
| 330 | |
| 331 | if let (Some(new_nick), Some(old_nick)) = (new_nick, old_nick) { |
| 332 | println!("Changing nickname from {old_nick} to {new_nick}"); |
| 333 | } |
| 334 | if let (Some(new_host), Some(old_host)) = (new_host, old_host) { |
| 335 | println!("Changing host from {old_host} to {new_host}"); |
| 336 | } |
| 337 | if let (Some(new_proto), Some(old_proto)) = (new_proto, old_proto) { |
| 338 | println!("Changing protocol from {old_proto} to {new_proto}"); |
| 339 | } |
| 340 | |
| 341 | let new_url = config.get_host_url(Some(server))?; |
| 342 | |
| 343 | if old_url != new_url { |
| 344 | if no_fingerprint { |
| 345 | config.delete_server_fingerprint(Some(&new_url))?; |
| 346 | } else { |
| 347 | update_server_fingerprint(&mut config, Some(&new_url)).await?; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if !y_or_n(force, "Continue?")? { |
| 352 | anyhow::bail!("Aborted"); |
| 353 | } |
| 354 | |
| 355 | config.save(); |
| 356 | |
| 357 | Ok(()) |
| 358 | } |
| 359 | |
| 360 | async fn exec_clear(_config: Config, paths: &SpacetimePaths, args: &ArgMatches) -> Result<(), anyhow::Error> { |
| 361 | let force = args.get_flag("force"); |
no test coverage detected
searching dependent graphs…