aboutsummaryrefslogtreecommitdiff
path: root/src/repo/repostate.rs
blob: ea3c5a6a0fc1ed8f59e716bdbb4228fc37842a27 (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
use super::Repo;

#[derive(Clone, Debug)]
pub enum RepoState {
    Local,
    Remote,
    Synced,
    Unknown,
}

impl std::fmt::Display for RepoState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        use ansi_term::Colour::{Blue, Green, Red, Yellow};

        match self {
            RepoState::Local => f.write_str(&Yellow.paint("LOCAL  ").to_string()),
            RepoState::Remote => f.write_str(&Blue.paint("REMOTE ").to_string()),
            RepoState::Synced => f.write_str(&Green.paint("SYNCED ").to_string()),
            RepoState::Unknown => f.write_str(&Red.paint("UNKNOWN").to_string()),
        }
    }
}

impl From<&Repo> for RepoState {
    fn from(repo: &Repo) -> Self {
        if repo.repo.is_some() && repo.forge.is_some() {
            RepoState::Synced
        } else if repo.repo.is_some() {
            RepoState::Local
        } else if repo.forge.is_some() {
            RepoState::Remote
        } else {
            RepoState::Unknown
        }
    }
}