From 4a5c32ba062ca6ba7fd27e89d2b2f46e4f2368fb Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 1 Apr 2024 15:43:30 +0100 Subject: feat(init): support multiple git_servers in line with initial merged nip34 spec --- src/repo_ref.rs | 11 ++++++----- src/sub_commands/init.rs | 33 +++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/repo_ref.rs b/src/repo_ref.rs index 2dab79c..3e8db64 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs @@ -20,7 +20,7 @@ pub struct RepoRef { pub description: String, pub identifier: String, pub root_commit: String, - pub git_server: String, + pub git_server: Vec, pub web: Vec, pub relays: Vec, pub maintainers: Vec, @@ -49,7 +49,8 @@ impl TryFrom for RepoRef { } if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("clone")) { - r.git_server = t.as_vec()[1].clone(); + r.git_server = t.as_vec().clone(); + r.git_server.remove(0); } if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("web")) { @@ -121,7 +122,7 @@ impl RepoRef { Tag::Description(self.description.clone()), Tag::Generic( nostr::TagKind::Custom("clone".to_string()), - vec![self.git_server.clone()], + self.git_server.clone(), ), Tag::Generic(nostr::TagKind::Custom("web".to_string()), self.web.clone()), Tag::Generic( @@ -303,7 +304,7 @@ mod tests { name: "test name".to_string(), description: "test description".to_string(), root_commit: "5e664e5a7845cd1373c79f580ca4fe29ab5b34d2".to_string(), - git_server: "https://localhost:1000".to_string(), + git_server: vec!["https://localhost:1000".to_string()], web: vec![ "https://exampleproject.xyz".to_string(), "https://gitworkshop.dev/123".to_string(), @@ -394,7 +395,7 @@ mod tests { fn git_server() { assert_eq!( RepoRef::try_from(create()).unwrap().git_server, - "https://localhost:1000", + vec!["https://localhost:1000"], ) } diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 56129a6..4b35d28 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -25,7 +25,7 @@ pub struct SubCommandArgs { description: Option, #[clap(long)] /// git server url users can clone from - clone_url: Option, + clone_url: Vec, #[clap(short, long, value_parser, num_args = 1..)] /// homepage web: Vec, @@ -129,19 +129,24 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { )?, }; - let git_server = match &args.clone_url { - Some(t) => t.clone(), - None => Interactor::default().input( - PromptInputParms::default() - .with_prompt("clone url") - .with_default(if let Some(repo_ref) = &repo_ref { - repo_ref.git_server.clone() - } else if let Ok(git_repo) = git_repo.get_origin_url() { - git_repo - } else { - String::new() - }), - )?, + let git_server = if args.clone_url.is_empty() { + Interactor::default() + .input( + PromptInputParms::default() + .with_prompt("clone url") + .with_default(if let Some(repo_ref) = &repo_ref { + repo_ref.git_server.clone().join(" ") + } else if let Ok(git_repo) = git_repo.get_origin_url() { + git_repo + } else { + String::new() + }), + )? + .split(' ') + .map(std::string::ToString::to_string) + .collect() + } else { + args.clone_url.clone() }; let web: Vec = if args.web.is_empty() { -- cgit v1.2.3