From a4bcaf98cc7a00a71f34ed382dc65414eaec5bff Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 17 Sep 2024 13:23:22 +0100 Subject: feat(remote): store successful protocol in config if another protocol was tried first and failed --- src/lib/git/nostr_url.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/lib') 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 @@ use core::fmt; use std::{collections::HashSet, str::FromStr}; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{anyhow, bail, Context, Error, Result}; use nostr::nips::nip01::Coordinate; use nostr_sdk::{PublicKey, Url}; @@ -34,6 +34,25 @@ impl fmt::Display for ServerProtocol { } } +impl FromStr for ServerProtocol { + type Err = Error; + + // Method to convert a string to a ServerProtocol variant + fn from_str(s: &str) -> Result { + match s { + "http" => Ok(ServerProtocol::Http), + "https" => Ok(ServerProtocol::Https), + "ftp" => Ok(ServerProtocol::Ftp), + "ssh" => Ok(ServerProtocol::Ssh), + "git" => Ok(ServerProtocol::Git), + "filesystem" => Ok(ServerProtocol::Filesystem), + "http (unauthenticated)" => Ok(ServerProtocol::UnauthHttp), + "https (unauthenticated)" => Ok(ServerProtocol::UnauthHttps), + _ => bail!("not listed as a server protocol"), + } + } +} + #[derive(Debug, PartialEq)] pub struct NostrUrlDecoded { pub original_string: String, -- cgit v1.2.3