use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, ListOptions}, cmd_update, error::MLE}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct List { pub id: String, pub mc_version: String, pub modloader: Modloader, pub download_folder: String, } pub async fn list(config: Cfg, input: Input) -> MLE<()> { match input.clone().list_options.unwrap() { ListOptions::Add => { add(config, input) }, ListOptions::Change => { change(config, input) }, ListOptions::Remove => { remove(config, input) }, ListOptions::Version => { version(config, input).await } } } pub fn get_current_list(config: Cfg) -> MLE { let id = config_get_current_list(config.clone())?; lists_get(config, id) } fn add(config: Cfg, input: Input) -> MLE<()> { let id = input.list_id.unwrap(); let mc_version = input.list_mcversion.unwrap(); let mod_loader = input.modloader.unwrap(); let download_folder = input.directory.unwrap(); lists_insert(config, id, mc_version, mod_loader, download_folder) } fn change(config: Cfg, input: Input) -> MLE<()> { println!("Change default list to: {}", input.clone().list.unwrap().id); config_change_current_list(config, input.list.unwrap().id) } fn remove(config: Cfg, input: Input) -> MLE<()> { lists_remove(config, input.list.unwrap().id) } ///Changing the current lists version and updating it /// /// #Arguments /// /// * `config` - The current config /// * `args` - All args, to extract the new version async fn version(config: Cfg, input: Input) -> MLE<()> { println!("Change version for list {} to minecraft version: {}", input.clone().list.unwrap().id, input.clone().list_mcversion.unwrap()); lists_version(config.clone(), input.clone().list.ok_or("").unwrap().id, input.clone().list_mcversion.ok_or("").unwrap())?; //Linebreak readability println!(""); println!("Check for updates for new minecraft version in list {}", input.clone().list.unwrap().id); cmd_update(config, vec![input.list.ok_or("").unwrap()], true, input.direct_download, input.delete_old).await }