summaryrefslogblamecommitdiff
path: root/src/main.rs
blob: 32727c7a6ec592dda520eedbac929c9e0aa1eb66 (plain) (tree)
1
2
3
4
5
6
7
8
                        
 
                                                                                                     


                 
                                                    
    



                                                      




                                             
    

                                                             

                              
                             

         
 

                                          
                                             
















                                         


                               














                                                                                   
 
use std::{env, process};

use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io, modification, setup};

#[tokio::main]
async fn main() {
    let config = Cfg::init("modlist.toml").unwrap();
    
    let mut args: Vec<String> = env::args().collect();
    args.reverse();
    args.pop();
    args.reverse();

    if args.is_empty() {
        println!("Please enter an argument");
        process::exit(1);
    };
    
    let input = match get_input(config.clone(), args).await {
        Ok(i) => i,
        Err(e) => {
            println!("{}", e);
            process::exit(1);
        }
    };

    match input.clone().command.unwrap() {
        Cmd::Mod => {
            modification(config, input).await
        },
        Cmd::List => {
            list(config, input).await
        },
        Cmd::Update => {
            update(config, input).await
        },
        Cmd::Download => {
            download(config, input).await
        },
        Cmd::Io => {
            io(config, input).await
        },
        Cmd::Version => {
            show_version();
            Ok(())
        },
        Cmd::Setup => {
            setup(config).await
        },
    }.unwrap()
}

fn show_version() {
    match std::env::var("DEV") {
        Ok(dev) => {
            let devint = dev.parse::<i32>().unwrap();
            if devint >= 1 {
                println!("Modlist by FxQnLr v{} (DEV)", env!("CARGO_PKG_VERSION"));
            } else {
                println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION"));
            }
        },
        Err(..) => println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")),
    }
}