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
use serde::{Deserialize, Serialize};
use url::Url;

/// Represents a input url from the user.
///
/// Available patterns are:
///
/// * `<scheme>://[<username>[:<password>]@]<host>/<path-to-repo>.git`
///   - Available schemes are: `http[s]`, `ssh` and `git`.
///   - Example: https://github.com/user/repo
/// * `<username>@<host>:<path-to-repo>`
///   - Equivalent to `ssh://<username>@<host>/<path-to-repo>.git`
/// * `<username>@<host>:<path-to-repo>`
///   - Equivalent to `ssh://<username>@<host>/<path-to-repo>.git`
/// * `<path-to-repo>`
#[derive(Debug, Serialize, Deserialize)]
pub enum Query {
    Url(Url),
    Scp(ScpPath),
    Abbrev(AbbrevUrl),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ScpPath {
    pub host: String,
    pub username: String,
    pub path: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AbbrevUrl {
    pub username: String,
    pub path: String,
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub enum Scheme {
    #[serde(rename = "http")]
    Http,
    #[serde(rename = "https")]
    Https,
    #[serde(rename = "git")]
    Git,
    #[serde(rename = "ssh")]
    Ssh,
}

mod abbrev;
mod inner;
mod scheme;
mod scp;