repo_cli/remote.rs
1use crate::{Query, ScpPath};
2use anyhow::Result;
3use serde::{Deserialize, Serialize};
4use url::Url;
5
6#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
7pub struct Remote {
8 pub name: String,
9 pub url: Url,
10}
11
12impl Remote {
13 pub fn new<U: Into<Url>>(url: U) -> Self {
14 Self {
15 name: "origin".to_owned(),
16 url: url.into(),
17 }
18 }
19
20 pub fn with_name<U: Into<Url>>(name: &str, url: U) -> Self {
21 Self {
22 name: name.to_owned(),
23 url: url.into(),
24 }
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 // use super::*;
31 // use std::str::FromStr;
32
33 // #[test]
34 // fn from_url() {
35 // let name = "repo";
36 // let url = Url::parse("https://github.com/edeneast/repo").unwrap();
37
38 // let remote = Remote::from_url(name, url).unwrap();
39 // assert_eq!(remote.name, name);
40 // assert_eq!(remote.url.scheme(), "https");
41 // assert_eq!(remote.url.host_str(), Some("github.com"));
42 // assert_eq!(remote.url.path(), "/edeneast/repo");
43 // }
44
45 // #[test]
46 // fn from_scp() {
47 // let name = "repo";
48 // let scp = ScpPath::from_str("git@github.com:edeneast/repo").unwrap();
49
50 // let remote = Remote::from_scp(name, scp).unwrap();
51 // assert_eq!(remote.name, name);
52 // assert_eq!(remote.url.scheme(), "ssh");
53 // assert_eq!(remote.url.host_str(), Some("github.com"));
54 // assert_eq!(remote.url.path(), "/edeneast/repo");
55 // }
56}