diff options
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 12 | ||||
| -rw-r--r-- | src/lib/mod.rs | 21 | ||||
| -rw-r--r-- | src/lib/repo_ref.rs | 5 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 70a2cd9..5c090ae 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -10,6 +10,7 @@ use anyhow::{Context, Result, bail}; | |||
| 10 | use console::Style; | 10 | use console::Style; |
| 11 | use dialoguer::theme::{ColorfulTheme, Theme}; | 11 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 12 | use ngit::{ | 12 | use ngit::{ |
| 13 | UrlWithoutSlash, | ||
| 13 | cli_interactor::{PromptChoiceParms, PromptConfirmParms, PromptMultiChoiceParms}, | 14 | cli_interactor::{PromptChoiceParms, PromptConfirmParms, PromptMultiChoiceParms}, |
| 14 | client::{Params, send_events}, | 15 | client::{Params, send_events}, |
| 15 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, | 16 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, |
| @@ -231,7 +232,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 231 | repo_ref | 232 | repo_ref |
| 232 | .blossoms | 233 | .blossoms |
| 233 | .iter() | 234 | .iter() |
| 234 | .map(std::string::ToString::to_string) | 235 | .map(UrlWithoutSlash::to_string_without_trailing_slash) |
| 235 | .collect::<Vec<String>>() | 236 | .collect::<Vec<String>>() |
| 236 | // } else if user_ref.blossoms.read().is_empty() { | 237 | // } else if user_ref.blossoms.read().is_empty() { |
| 237 | // client.get_fallback_relays().clone() | 238 | // client.get_fallback_relays().clone() |
| @@ -290,7 +291,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 290 | } | 291 | } |
| 291 | } | 292 | } |
| 292 | if args.blossoms.is_empty() { | 293 | if args.blossoms.is_empty() { |
| 293 | let blossom = format_ngit_blossom_url_as_relay_url(ngit_relay)?; | 294 | let blossom = format_ngit_relay_url_as_blossom_url(ngit_relay)?; |
| 294 | if !blossoms_defaults.contains(&blossom) { | 295 | if !blossoms_defaults.contains(&blossom) { |
| 295 | blossoms_defaults.push(blossom); | 296 | blossoms_defaults.push(blossom); |
| 296 | } | 297 | } |
| @@ -483,8 +484,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 483 | blossoms_defaults, | 484 | blossoms_defaults, |
| 484 | selections, | 485 | selections, |
| 485 | |s| { | 486 | |s| { |
| 486 | Url::parse(s) | 487 | format_ngit_relay_url_as_blossom_url(s) |
| 487 | .map(|_| s.to_string()) | ||
| 488 | .context(format!("Invalid blossom URL format: {s}")) | 488 | .context(format!("Invalid blossom URL format: {s}")) |
| 489 | }, | 489 | }, |
| 490 | )?; | 490 | )?; |
| @@ -974,10 +974,10 @@ fn format_ngit_relay_url_as_relay_url(url: &str) -> Result<String> { | |||
| 974 | Ok(format!("wss://{ngit_relay_url}")) | 974 | Ok(format!("wss://{ngit_relay_url}")) |
| 975 | } | 975 | } |
| 976 | 976 | ||
| 977 | fn format_ngit_blossom_url_as_relay_url(url: &str) -> Result<String> { | 977 | fn format_ngit_relay_url_as_blossom_url(url: &str) -> Result<String> { |
| 978 | let ngit_relay_url = normalize_ngit_relay_url(url)?; | 978 | let ngit_relay_url = normalize_ngit_relay_url(url)?; |
| 979 | if ngit_relay_url.contains("http://") { | 979 | if ngit_relay_url.contains("http://") { |
| 980 | return Ok(ngit_relay_url.to_string()); | 980 | return Ok(ngit_relay_url); |
| 981 | } | 981 | } |
| 982 | Ok(format!("https://{ngit_relay_url}")) | 982 | Ok(format!("https://{ngit_relay_url}")) |
| 983 | } | 983 | } |
diff --git a/src/lib/mod.rs b/src/lib/mod.rs index 2072a80..7c7bd6a 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs | |||
| @@ -8,9 +8,30 @@ pub mod repo_state; | |||
| 8 | 8 | ||
| 9 | use anyhow::{Result, anyhow}; | 9 | use anyhow::{Result, anyhow}; |
| 10 | use directories::ProjectDirs; | 10 | use directories::ProjectDirs; |
| 11 | use nostr_sdk::Url; | ||
| 11 | 12 | ||
| 12 | pub fn get_dirs() -> Result<ProjectDirs> { | 13 | pub fn get_dirs() -> Result<ProjectDirs> { |
| 13 | ProjectDirs::from("", "", "ngit").ok_or(anyhow!( | 14 | ProjectDirs::from("", "", "ngit").ok_or(anyhow!( |
| 14 | "should find operating system home directories with rust-directories crate" | 15 | "should find operating system home directories with rust-directories crate" |
| 15 | )) | 16 | )) |
| 16 | } | 17 | } |
| 18 | |||
| 19 | pub trait UrlWithoutSlash { | ||
| 20 | fn as_str_without_trailing_slash(&self) -> &str; | ||
| 21 | fn to_string_without_trailing_slash(&self) -> String; | ||
| 22 | } | ||
| 23 | |||
| 24 | impl UrlWithoutSlash for Url { | ||
| 25 | fn as_str_without_trailing_slash(&self) -> &str { | ||
| 26 | let url_str = self.as_str(); | ||
| 27 | if let Some(without) = url_str.strip_suffix('/') { | ||
| 28 | without | ||
| 29 | } else { | ||
| 30 | url_str | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | fn to_string_without_trailing_slash(&self) -> String { | ||
| 35 | self.as_str_without_trailing_slash().to_string() | ||
| 36 | } | ||
| 37 | } | ||
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 1a0fe85..df1427a 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs | |||
| @@ -18,6 +18,7 @@ use serde::{Deserialize, Serialize}; | |||
| 18 | #[cfg(not(test))] | 18 | #[cfg(not(test))] |
| 19 | use crate::client::Client; | 19 | use crate::client::Client; |
| 20 | use crate::{ | 20 | use crate::{ |
| 21 | UrlWithoutSlash, | ||
| 21 | cli_interactor::{ | 22 | cli_interactor::{ |
| 22 | Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms, | 23 | Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms, |
| 23 | }, | 24 | }, |
| @@ -204,7 +205,9 @@ impl RepoRef { | |||
| 204 | } else { | 205 | } else { |
| 205 | vec![Tag::custom( | 206 | vec![Tag::custom( |
| 206 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("blossoms")), | 207 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("blossoms")), |
| 207 | self.blossoms.iter().map(|r| r.to_string()), | 208 | self.blossoms |
| 209 | .iter() | ||
| 210 | .map(|r| r.to_string_without_trailing_slash()), | ||
| 208 | )] | 211 | )] |
| 209 | }, | 212 | }, |
| 210 | // code languages and hashtags | 213 | // code languages and hashtags |