summaryrefslogtreecommitdiff
path: root/src/project.rs
blob: e67fefc4ec03d34c21db3ee263d7dd670d60c662 (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
use crate::debian::Debian;
use crate::errors::BumperError;
use crate::python::Python;
use crate::rust::Rust;
use std::path::Path;

pub enum ProjectKind {
    Rust(Rust),
    Debian(Debian),
    Python(Python),
}

impl ProjectKind {
    pub fn detect<P: AsRef<Path>>(dirname: P) -> Result<Vec<ProjectKind>, BumperError> {
        let dirname = dirname.as_ref();
        let mut kinds = vec![];

        if let Ok(p) = Rust::new(dirname) {
            kinds.push(ProjectKind::Rust(p));
        }

        if let Ok(p) = Debian::new(dirname) {
            kinds.push(ProjectKind::Debian(p));
        }

        if let Ok(p) = Python::new(dirname) {
            kinds.push(ProjectKind::Python(p));
        }

        if kinds.is_empty() {
            Err(BumperError::UnknownProjectKind(dirname.to_path_buf()))
        } else {
            Ok(kinds)
        }
    }

    pub fn set_version(&mut self, version: &str) -> Result<(), BumperError> {
        match self {
            Self::Rust(ref mut rust) => rust.set_version(version)?,
            Self::Debian(ref mut debian) => debian.set_version(version)?,
            Self::Python(ref mut python) => python.set_version(version)?,
        }
        Ok(())
    }
}