aboutsummaryrefslogtreecommitdiff
path: root/src/local/update.rs
blob: 95057a4f65a57d333d8cb9065af6f84a6aa90bba (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::fmt::Display;

#[derive(Debug)]
pub enum UpdateResult {
    NoChanges {
        name: String,
    },
    Dirty {
        name: String,
    },
    Merged {
        name: String,
    },
    Error {
        name: String,
        error: super::RepoError,
    },
}

impl UpdateResult {
    pub fn err(name: String, error: super::RepoError) -> UpdateResult {
        UpdateResult::Error { name, error }
    }

    pub fn merged(name: String) -> UpdateResult {
        UpdateResult::Merged { name }
    }

    pub fn dirty(name: String) -> UpdateResult {
        UpdateResult::Dirty { name }
    }

    pub fn no_changes(name: String) -> UpdateResult {
        UpdateResult::NoChanges { name }
    }
}

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

        match self {
            UpdateResult::NoChanges { name } => {
                f.write_fmt(format_args!("{} {}", Blue.paint("FETCHED"), name))
            }
            UpdateResult::Dirty { name } => {
                f.write_fmt(format_args!("{} {}", Yellow.paint("DIRTY  "), name))
            }
            UpdateResult::Merged { name } => {
                f.write_fmt(format_args!("{} {}", Green.paint("PULLED "), name))
            }
            UpdateResult::Error { name, error } => {
                f.write_fmt(format_args!("{} {} [{}]", Red.paint("ERROR  "), name, error))
            }
        }
    }
}