upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/mod.rs
blob: 7c7bd6ab5205e9bc6bfb9b65666991f190a8fded (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
pub mod cli_interactor;
pub mod client;
pub mod git;
pub mod git_events;
pub mod login;
pub mod repo_ref;
pub mod repo_state;

use anyhow::{Result, anyhow};
use directories::ProjectDirs;
use nostr_sdk::Url;

pub fn get_dirs() -> Result<ProjectDirs> {
    ProjectDirs::from("", "", "ngit").ok_or(anyhow!(
        "should find operating system home directories with rust-directories crate"
    ))
}

pub trait UrlWithoutSlash {
    fn as_str_without_trailing_slash(&self) -> &str;
    fn to_string_without_trailing_slash(&self) -> String;
}

impl UrlWithoutSlash for Url {
    fn as_str_without_trailing_slash(&self) -> &str {
        let url_str = self.as_str();
        if let Some(without) = url_str.strip_suffix('/') {
            without
        } else {
            url_str
        }
    }

    fn to_string_without_trailing_slash(&self) -> String {
        self.as_str_without_trailing_slash().to_string()
    }
}