diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-17 13:23:22 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-17 13:23:22 +0100 |
| commit | a4bcaf98cc7a00a71f34ed382dc65414eaec5bff (patch) | |
| tree | 661bcac2b381d232be2488248bc899c48e50fb7e /src/lib/git | |
| parent | 12fb184cd1a875704d4f187531aa1638513a3dab (diff) | |
feat(remote): store successful protocol in config
if another protocol was tried first and failed
Diffstat (limited to 'src/lib/git')
| -rw-r--r-- | src/lib/git/nostr_url.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 6fcc11d..42b0ac9 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::fmt; | 1 | use core::fmt; |
| 2 | use std::{collections::HashSet, str::FromStr}; | 2 | use std::{collections::HashSet, str::FromStr}; |
| 3 | 3 | ||
| 4 | use anyhow::{anyhow, bail, Context, Result}; | 4 | use anyhow::{anyhow, bail, Context, Error, Result}; |
| 5 | use nostr::nips::nip01::Coordinate; | 5 | use nostr::nips::nip01::Coordinate; |
| 6 | use nostr_sdk::{PublicKey, Url}; | 6 | use nostr_sdk::{PublicKey, Url}; |
| 7 | 7 | ||
| @@ -34,6 +34,25 @@ impl fmt::Display for ServerProtocol { | |||
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | impl FromStr for ServerProtocol { | ||
| 38 | type Err = Error; | ||
| 39 | |||
| 40 | // Method to convert a string to a ServerProtocol variant | ||
| 41 | fn from_str(s: &str) -> Result<ServerProtocol> { | ||
| 42 | match s { | ||
| 43 | "http" => Ok(ServerProtocol::Http), | ||
| 44 | "https" => Ok(ServerProtocol::Https), | ||
| 45 | "ftp" => Ok(ServerProtocol::Ftp), | ||
| 46 | "ssh" => Ok(ServerProtocol::Ssh), | ||
| 47 | "git" => Ok(ServerProtocol::Git), | ||
| 48 | "filesystem" => Ok(ServerProtocol::Filesystem), | ||
| 49 | "http (unauthenticated)" => Ok(ServerProtocol::UnauthHttp), | ||
| 50 | "https (unauthenticated)" => Ok(ServerProtocol::UnauthHttps), | ||
| 51 | _ => bail!("not listed as a server protocol"), | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 37 | #[derive(Debug, PartialEq)] | 56 | #[derive(Debug, PartialEq)] |
| 38 | pub struct NostrUrlDecoded { | 57 | pub struct NostrUrlDecoded { |
| 39 | pub original_string: String, | 58 | pub original_string: String, |