summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 17ad6b9a44545dde27ca29fb9ff2ea4ce0ad149f (plain) (blame)
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
pub mod apis;
pub mod config;
pub mod commands;
pub mod input;
pub mod db;
pub mod error;
pub mod files;

use std::{io::{Error, ErrorKind}, path::Path};

pub use apis::*;
pub use commands::*;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Modloader {
    Fabric,
    Forge
}

impl Modloader {
    fn stringify(&self) -> String {
        match self {
            Modloader::Fabric => String::from("fabric"),
            Modloader::Forge => String::from("forge"),
        }
    }

    fn from(string: &str) -> Result<Modloader, Box<Error>> {
        match string {
            "forge" => Ok(Modloader::Forge),
            "fabric" => Ok(Modloader::Fabric),
            _ => Err(Box::new(Error::new(ErrorKind::InvalidData, "UNKNOWN_MODLOADER")))
        }
    }
}

pub fn devdir(path: &str) -> String {
    let p = Path::new(path);
    let dev = std::env::var("DEV");
    let lvl = match dev {
        Ok(dev) => dev.parse::<i32>().unwrap(),
        Err(..) => 0,
    };
    if lvl >= 1 {
        format!("./dev/{}", p.file_name().unwrap().to_str().unwrap())
    } else {
        String::from(path)
    }
}