upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/init.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-27 17:08:25 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-27 17:08:25 +0000
commit83448a99aaf18c7a045a081c5de0c22bc4a83de1 (patch)
tree28076a33b40e63937d79a8fe8d54b58d42db092c /src/bin/ngit/sub_commands/init.rs
parent5478aa74cc26452809e499a461067ca9744cb7ce (diff)
chore: bump rust-nosrt v0.37.0
use RelayUrl in repo_ref which I had resisted as it mutates relay urls when printed to append a slash
Diffstat (limited to 'src/bin/ngit/sub_commands/init.rs')
-rw-r--r--src/bin/ngit/sub_commands/init.rs63
1 files changed, 44 insertions, 19 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index 2af6aef..0d3e344 100644
--- a/src/bin/ngit/sub_commands/init.rs
+++ b/src/bin/ngit/sub_commands/init.rs
@@ -3,7 +3,7 @@ use std::collections::HashMap;
3use anyhow::{Context, Result}; 3use anyhow::{Context, Result};
4use ngit::cli_interactor::PromptConfirmParms; 4use ngit::cli_interactor::PromptConfirmParms;
5use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32}; 5use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32};
6use nostr_sdk::Kind; 6use nostr_sdk::{Kind, RelayUrl};
7 7
8use crate::{ 8use crate::{
9 cli::{extract_signer_cli_arguments, Cli}, 9 cli::{extract_signer_cli_arguments, Cli},
@@ -323,24 +323,45 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
323 323
324 // TODO: check if relays are free to post to so contributors can submit patches 324 // TODO: check if relays are free to post to so contributors can submit patches
325 // TODO: recommend some reliable free ones 325 // TODO: recommend some reliable free ones
326 let relays: Vec<String> = if args.relays.is_empty() { 326 let relays: Vec<RelayUrl> = {
327 Interactor::default() 327 let mut default = if let Ok(config) = &repo_config_result {
328 .input( 328 config.relays.clone().join(" ")
329 PromptInputParms::default() 329 } else if let Some(repo_ref) = &repo_ref {
330 .with_prompt("relays") 330 repo_ref
331 .with_default(if let Ok(config) = &repo_config_result { 331 .relays
332 config.relays.clone().join(" ") 332 .iter()
333 } else if let Some(repo_ref) = &repo_ref { 333 .map(std::string::ToString::to_string)
334 repo_ref.relays.clone().join(" ") 334 .collect::<Vec<String>>()
335 } else { 335 .join(" ")
336 user_ref.relays.write().join(" ") 336 } else {
337 }), 337 user_ref.relays.write().join(" ")
338 )? 338 };
339 .split(' ') 339 'outer: loop {
340 .map(std::string::ToString::to_string) 340 let relays: Vec<String> = if args.relays.is_empty() {
341 .collect() 341 Interactor::default()
342 } else { 342 .input(
343 args.relays.clone() 343 PromptInputParms::default()
344 .with_prompt("relays")
345 .with_default(default),
346 )?
347 .split(' ')
348 .map(std::string::ToString::to_string)
349 .collect()
350 } else {
351 args.relays.clone()
352 };
353 let mut relay_urls = vec![];
354 for r in &relays {
355 if let Ok(r) = RelayUrl::parse(r) {
356 relay_urls.push(r);
357 } else {
358 eprintln!("{r} is not a valid relay url");
359 default = relays.join(" ");
360 continue 'outer;
361 }
362 }
363 break relay_urls;
364 }
344 }; 365 };
345 366
346 let earliest_unique_commit = match &args.earliest_unique_commit { 367 let earliest_unique_commit = match &args.earliest_unique_commit {
@@ -415,6 +436,10 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
415 false, 436 false,
416 )?; 437 )?;
417 438
439 let relays = relays
440 .iter()
441 .map(std::string::ToString::to_string)
442 .collect::<Vec<String>>();
418 // if yaml file doesnt exist or needs updating 443 // if yaml file doesnt exist or needs updating
419 if match &repo_config_result { 444 if match &repo_config_result {
420 Ok(config) => { 445 Ok(config) => {