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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::path::PathBuf;
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
pub struct Location {
pub location: String,
}
impl Location {
pub fn new(loc: &str) -> Self {
Self {
location: loc.to_string(),
}
}
pub fn url(&self) -> Option<String> {
if self.location.starts_with("http://") || self.location.starts_with("https://") {
Some(self.location.clone())
} else {
None
}
}
pub fn git(&self) -> Option<String> {
if self.git_https().is_some() || self.git_ssh().is_some() {
Some(self.location.clone())
} else {
None
}
}
pub fn git_https(&self) -> Option<String> {
if self.location.starts_with("https://") && self.location.ends_with(".git") {
Some(self.location.clone())
} else {
None
}
}
pub fn git_ssh(&self) -> Option<String> {
if self.location.starts_with("git@") && self.location.ends_with(".git") {
Some(self.location.clone())
} else {
None
}
}
pub fn path(&self) -> Option<PathBuf> {
if self.url().is_none() && self.git().is_none() {
Some(PathBuf::from(&self.location))
} else {
None
}
}
}