diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-04-01 15:43:30 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-04-08 16:10:05 +0100 |
| commit | 4a5c32ba062ca6ba7fd27e89d2b2f46e4f2368fb (patch) | |
| tree | 47dac8fc609a34d088f01b825f3fa50cc14e55c0 | |
| parent | 8c5a484a0e010eaa566c17acd8b344114b68caa6 (diff) | |
feat(init): support multiple git_servers
in line with initial merged nip34 spec
| -rw-r--r-- | src/repo_ref.rs | 11 | ||||
| -rw-r--r-- | 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 { | |||
| 20 | pub description: String, | 20 | pub description: String, |
| 21 | pub identifier: String, | 21 | pub identifier: String, |
| 22 | pub root_commit: String, | 22 | pub root_commit: String, |
| 23 | pub git_server: String, | 23 | pub git_server: Vec<String>, |
| 24 | pub web: Vec<String>, | 24 | pub web: Vec<String>, |
| 25 | pub relays: Vec<String>, | 25 | pub relays: Vec<String>, |
| 26 | pub maintainers: Vec<PublicKey>, | 26 | pub maintainers: Vec<PublicKey>, |
| @@ -49,7 +49,8 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("clone")) { | 51 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("clone")) { |
| 52 | r.git_server = t.as_vec()[1].clone(); | 52 | r.git_server = t.as_vec().clone(); |
| 53 | r.git_server.remove(0); | ||
| 53 | } | 54 | } |
| 54 | 55 | ||
| 55 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("web")) { | 56 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("web")) { |
| @@ -121,7 +122,7 @@ impl RepoRef { | |||
| 121 | Tag::Description(self.description.clone()), | 122 | Tag::Description(self.description.clone()), |
| 122 | Tag::Generic( | 123 | Tag::Generic( |
| 123 | nostr::TagKind::Custom("clone".to_string()), | 124 | nostr::TagKind::Custom("clone".to_string()), |
| 124 | vec![self.git_server.clone()], | 125 | self.git_server.clone(), |
| 125 | ), | 126 | ), |
| 126 | Tag::Generic(nostr::TagKind::Custom("web".to_string()), self.web.clone()), | 127 | Tag::Generic(nostr::TagKind::Custom("web".to_string()), self.web.clone()), |
| 127 | Tag::Generic( | 128 | Tag::Generic( |
| @@ -303,7 +304,7 @@ mod tests { | |||
| 303 | name: "test name".to_string(), | 304 | name: "test name".to_string(), |
| 304 | description: "test description".to_string(), | 305 | description: "test description".to_string(), |
| 305 | root_commit: "5e664e5a7845cd1373c79f580ca4fe29ab5b34d2".to_string(), | 306 | root_commit: "5e664e5a7845cd1373c79f580ca4fe29ab5b34d2".to_string(), |
| 306 | git_server: "https://localhost:1000".to_string(), | 307 | git_server: vec!["https://localhost:1000".to_string()], |
| 307 | web: vec![ | 308 | web: vec![ |
| 308 | "https://exampleproject.xyz".to_string(), | 309 | "https://exampleproject.xyz".to_string(), |
| 309 | "https://gitworkshop.dev/123".to_string(), | 310 | "https://gitworkshop.dev/123".to_string(), |
| @@ -394,7 +395,7 @@ mod tests { | |||
| 394 | fn git_server() { | 395 | fn git_server() { |
| 395 | assert_eq!( | 396 | assert_eq!( |
| 396 | RepoRef::try_from(create()).unwrap().git_server, | 397 | RepoRef::try_from(create()).unwrap().git_server, |
| 397 | "https://localhost:1000", | 398 | vec!["https://localhost:1000"], |
| 398 | ) | 399 | ) |
| 399 | } | 400 | } |
| 400 | 401 | ||
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 { | |||
| 25 | description: Option<String>, | 25 | description: Option<String>, |
| 26 | #[clap(long)] | 26 | #[clap(long)] |
| 27 | /// git server url users can clone from | 27 | /// git server url users can clone from |
| 28 | clone_url: Option<String>, | 28 | clone_url: Vec<String>, |
| 29 | #[clap(short, long, value_parser, num_args = 1..)] | 29 | #[clap(short, long, value_parser, num_args = 1..)] |
| 30 | /// homepage | 30 | /// homepage |
| 31 | web: Vec<String>, | 31 | web: Vec<String>, |
| @@ -129,19 +129,24 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 129 | )?, | 129 | )?, |
| 130 | }; | 130 | }; |
| 131 | 131 | ||
| 132 | let git_server = match &args.clone_url { | 132 | let git_server = if args.clone_url.is_empty() { |
| 133 | Some(t) => t.clone(), | 133 | Interactor::default() |
| 134 | None => Interactor::default().input( | 134 | .input( |
| 135 | PromptInputParms::default() | 135 | PromptInputParms::default() |
| 136 | .with_prompt("clone url") | 136 | .with_prompt("clone url") |
| 137 | .with_default(if let Some(repo_ref) = &repo_ref { | 137 | .with_default(if let Some(repo_ref) = &repo_ref { |
| 138 | repo_ref.git_server.clone() | 138 | repo_ref.git_server.clone().join(" ") |
| 139 | } else if let Ok(git_repo) = git_repo.get_origin_url() { | 139 | } else if let Ok(git_repo) = git_repo.get_origin_url() { |
| 140 | git_repo | 140 | git_repo |
| 141 | } else { | 141 | } else { |
| 142 | String::new() | 142 | String::new() |
| 143 | }), | 143 | }), |
| 144 | )?, | 144 | )? |
| 145 | .split(' ') | ||
| 146 | .map(std::string::ToString::to_string) | ||
| 147 | .collect() | ||
| 148 | } else { | ||
| 149 | args.clone_url.clone() | ||
| 145 | }; | 150 | }; |
| 146 | 151 | ||
| 147 | let web: Vec<String> = if args.web.is_empty() { | 152 | let web: Vec<String> = if args.web.is_empty() { |