summaryrefslogblamecommitdiff
path: root/src/lib.rs
blob: 8d97d1a050b00c99f0a7dcf4a250a27b0e2e0d60 (plain) (tree)
1
2
3
4
5
6
7
8
9
             



                 
              
              
 
                                    
 
                
                    
                                     
 
                                      



                    

                
                                                 


                                              
                                                                                 
         

     
 








                                                                        












                                                                     
pub mod apis;
pub mod config;
pub mod commands;
pub mod input;
pub mod db;
pub mod error;
pub mod files;

use std::{path::Path, fmt::Display};

pub use apis::*;
pub use commands::*;
use error::{MLE, ErrorType, MLError};

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

impl Modloader {
    pub fn from(string: &str) -> MLE<Modloader> {
        match string {
            "forge" => Ok(Modloader::Forge),
            "fabric" => Ok(Modloader::Fabric),
            _ => Err(MLError::new(ErrorType::ArgumentError, "UNKNOWN_MODLOADER"))
        }
    }
}

impl Display for Modloader {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Modloader::Fabric => write!(f, "fabric"),
            Modloader::Forge => write!(f, "forge"),
        }
    }
}

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)
    }
}