From f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Jan 2023 18:37:42 +0100 Subject: input mostly inplemented, mods missing --- src/apis/modrinth.rs | 6 +-- src/commands/download.rs | 11 +++-- src/commands/io.rs | 30 ++++++------- src/commands/list.rs | 73 +++++++++--------------------- src/commands/mod.rs | 12 ++--- src/commands/update.rs | 18 +++++--- src/db.rs | 13 +++--- src/error.rs | 12 ++++- src/files.rs | 6 +-- src/input.rs | 115 +++++++++++++++++++++++++++-------------------- src/lib.rs | 6 +-- src/main.rs | 47 +++++++++++++++++-- 12 files changed, 194 insertions(+), 155 deletions(-) (limited to 'src') diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 78073e6..9890cf2 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -3,7 +3,7 @@ use chrono::{DateTime, FixedOffset}; use reqwest::Client; use serde::Deserialize; -use crate::{Modloader, List}; +use crate::{Modloader, List, error::{MLE, MLError, ErrorType}}; #[derive(Debug, Deserialize, Clone)] pub struct Project { @@ -177,9 +177,9 @@ pub async fn get_raw_versions(api: String, versions: Vec) -> Vec) -> Result> { +pub fn extract_current_version(versions: Vec) -> MLE { match versions.len() { - 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))), + 0 => Err(MLError::new(ErrorType::ModError, "NO_VERSIONS_AVAILABLE")), 1.. => { let mut times: Vec<(String, DateTime)> = vec![]; for ver in versions { diff --git a/src/commands/download.rs b/src/commands/download.rs index b958bf3..0f63876 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,7 +1,7 @@ -use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions}; +use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions, error::{MLE, ErrorType, MLError}}; use crate::{List, get_current_list, config::Cfg, input::Input}; -pub async fn download(config: Cfg, input: Input) -> Result<(), Box> { +pub async fn download(config: Cfg, input: Input) -> MLE<()> { let mut liststack: Vec = vec![]; if input.all_lists { @@ -18,7 +18,10 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box Ok(i), + Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), + }?; let mut to_download: Vec = vec![]; //(mod_id, version_id) @@ -33,7 +36,7 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box Result> { + pub fn from(config: Cfg, list_id: String, download: bool) -> MLE { let list = lists_get(config.clone(), String::from(&list_id))?; @@ -32,26 +32,22 @@ impl ExportList { } } -pub async fn io(config: Cfg, input: Input) -> Result<(), Box> { +pub async fn io(config: Cfg, input: Input) -> MLE<()> { - match input.subcommand.clone().ok_or("INVALID_INPUT")? { - Subcmd::Export => { export(config, input)? }, - Subcmd::Import => { import(config, input.args).await? }, - _ => { }, + match input.clone().io_options.unwrap() { + IoOptions::Export => { export(config, input)? }, + IoOptions::Import => { import(config, input).await? }, } Ok(()) } -fn export(config: Cfg, input: Input) -> Result<(), Box> { +fn export(config: Cfg, input: Input) -> MLE<()> { let mut list_ids: Vec = vec![]; if input.all_lists { list_ids = lists_get_all_ids(config.clone())?; } else { - let args = input.args.ok_or("NO_ARGS")?; - for arg in args { - list_ids.push(lists_get(config.clone(), arg)?.id); - } + list_ids.push(lists_get(config.clone(), input.list.unwrap().id)?.id); } let mut lists: Vec = vec![]; for list_id in list_ids { @@ -68,10 +64,10 @@ fn export(config: Cfg, input: Input) -> Result<(), Box> { Ok(()) } -async fn import(config: Cfg, args: Option>) -> Result<(), Box> { +async fn import(config: Cfg, input: Input) -> MLE<()> { - let filestr: String = match args { - Some(args) => String::from(&args[0]), + let filestr: String = match input.file { + Some(args) => String::from(args), None => String::from(devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str())), }; @@ -83,14 +79,14 @@ async fn import(config: Cfg, args: Option>) -> Result<(), Box = exportlist.mods.split("|").collect(); let mut mod_ids = vec![]; for mod_id in mods { mod_ids.push(String::from(mod_id)); }; - mod_add(config.clone(), mod_ids, list.clone(), false).await?; + //mod_add(config.clone(), mod_ids, list.clone(), false).await?; } Ok(()) } diff --git a/src/commands/list.rs b/src/commands/list.rs index 2fec1c7..bc58787 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,6 +1,4 @@ -use std::io::{Error, ErrorKind}; - -use crate::{db::{lists_insert, lists_remove, config_change_current_list, lists_get_all_ids, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, ListOptions}, /*cmd_update,*/ error::{MLE, ErrorType, MLError}, /*modrinth::MCVersionType*/}; +use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get}, Modloader, config::Cfg, input::{Input, ListOptions}, /*cmd_update,*/ error::MLE, /*modrinth::MCVersionType*/}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct List { @@ -9,78 +7,49 @@ pub struct List { pub modloader: Modloader, pub download_folder: String, } -/* -pub async fn list(config: Cfg, input: Input) -> Result<(), Box> { - match input.list_options.ok_or("")? { +pub async fn list(config: Cfg, input: Input) -> MLE<()> { + + match input.clone().list_options.unwrap() { ListOptions::Add => { - match add(config, input.args.ok_or("")?) { - Ok(..) => Ok(()), - Err(e) => Err(Box::new(e)) - } + add(config, input) }, ListOptions::Change => { - change(config, input.args) + change(config, input) }, ListOptions::Remove => { - match remove(config, input.args.ok_or("")?) { - Ok(..) => Ok(()), - Err(e) => Err(Box::new(e)) - } + remove(config, input) }, + /* Subcmd::Version => { match version(config, Some(input.args.ok_or("NO_VERSION")?), Some(MCVersionType::Release)).await { Ok(..) => Ok(()), Err(e) => Err(Box::new(e)) } - } - _ => { - Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) - } + }*/ } } -*/ + pub fn get_current_list(config: Cfg) -> MLE { let id = config_get_current_list(config.clone())?; lists_get(config, id) } -fn add(config: Cfg, args: Vec) -> MLE<()> { - match args.len() { - 1 | 2 | 3 => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_FEW_ARGUMENTS")), - 4 => { - let id = String::from(&args[0]); - let mc_version = String::from(&args[1]); - let mod_loader = Modloader::from(&args[2])?; - let download_folder = String::from(&args[3]); - lists_insert(config, id, mc_version, mod_loader, download_folder) - }, - 5.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")), - _ => panic!("list arguments should never be zero or lower"), - } +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, args: Option>) -> Result<(), Box> { - let lists = lists_get_all_ids(config.clone())?; - if args.is_none() { println!("Currently selected list: {}", get_current_list(config)?.id); return Ok(()) }; - let argsvec = args.ok_or("BAH")?; - match argsvec.len() { - 1 => { - let list = String::from(&argsvec[0]); - if !lists.contains(&list) { return Err(Box::new(Error::new(ErrorKind::NotFound, "LIST_DOESNT_EXIST"))); }; - config_change_current_list(config, list) - }, - 2.. => Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_MANY_ARGUMENTS"))), - _ => panic!("list arguments should never lower than zero"), - } +fn change(config: Cfg, input: Input) -> MLE<()> { + //TODO reimplement current list + config_change_current_list(config, input.list.unwrap().id) } -fn remove(config: Cfg, args: Vec) -> MLE<()> { - match args.len() { - 1 => lists_remove(config, String::from(&args[0])), - 2.. => Err(MLError::new(ErrorType::ArgumentCountError, "TOO_MANY_ARGUMENTS")), - _ => panic!("list arguments should never be zero or lower"), - } +fn remove(config: Cfg, input: Input) -> MLE<()> { + lists_remove(config, input.list.unwrap().id) } /* diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 29fc600..527afc7 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,13 +1,13 @@ //pub mod modification; pub mod list; -//pub mod update; +pub mod update; //pub mod setup; -//pub mod download; -//pub mod io; +pub mod download; +pub mod io; //pub use modification::*; pub use list::*; -//pub use update::*; +pub use update::*; //pub use setup::*; -//pub use download::*; -//pub use io::*; +pub use download::*; +pub use io::*; diff --git a/src/commands/update.rs b/src/commands/update.rs index ca28130..068c3f3 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,5 +1,3 @@ -use std::io::{Error, ErrorKind}; - use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}, error::{MLE, MLError, ErrorType}}; pub async fn update(config: Cfg, input: Input) -> MLE<()> { @@ -93,7 +91,7 @@ pub async fn cmd_update(config: Cfg, liststack: Vec, clean: bool, direct_d Ok(()) } -async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> Result> { +async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> MLE { println!("Checking update for '{}' in {}", project.title, list.id); let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; @@ -114,14 +112,20 @@ async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) //get new versions print!(" | getting new version"); let current_str = extract_current_version(applicable_versions.clone())?; - let current_ver = applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("")?; + let current_ver = match applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("!no current version in applicable_versions") { + Ok(v) => Ok(v), + Err(e) => Err(MLError::new(ErrorType::Other, e)), + }?; current.push(current_ver.clone()); - let link = current_ver.files.into_iter().find(|f| f.primary).ok_or("")?.url; - userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id)?; + let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") { + Ok(p) => Ok(p), + Err(e) => Err(MLError::new(ErrorType::Other, e)), + }?.url; + userlist_change_versions(config, list.id, current_str, versions.join("|"), link, project.id); } - if current.is_empty() { return Err(Box::new(Error::new(ErrorKind::NotFound, "NO_UPDATE_AVAILABLE"))) }; + if current.is_empty() { return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")) }; println!(" | ✔️"); Ok(current[0].clone()) diff --git a/src/db.rs b/src/db.rs index 06c2459..119b2a5 100644 --- a/src/db.rs +++ b/src/db.rs @@ -177,7 +177,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE> { } -pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<(), Box> { +pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -186,7 +186,7 @@ pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<( } -pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> Result> { +pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); @@ -201,12 +201,12 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St }; match version.is_empty() { - true => Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), + true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), false => Ok(version), } } -pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result, Box> { +pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> MLE> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -221,7 +221,7 @@ pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: Stri versions.push((out[0].to_owned(), out[1].to_owned())); }; - if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + if versions.is_empty() { return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); }; Ok(versions) } @@ -349,6 +349,7 @@ pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result MLE<()> { println!("Creating list {}", id); @@ -420,7 +421,7 @@ pub fn lists_get_all_ids(config: Cfg) -> MLE> { } //config -pub fn config_change_current_list(config: Cfg, id: String) -> Result<(), Box> { +pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; diff --git a/src/error.rs b/src/error.rs index dbe7224..a1f5f2e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,9 +15,11 @@ pub enum ErrorType { ArgumentCountError, ConfigError, DBError, + ModError, LibToml, LibSql, LibReq, + LibChrono, IoError, Other, } @@ -31,13 +33,15 @@ impl std::error::Error for MLError { impl fmt::Display for MLError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.etype { - ErrorType::ArgumentError => write!(f, "Wrong argument"), + ErrorType::ArgumentError => write!(f, "User input not accepted: {}", self.message), ErrorType::ArgumentCountError => write!(f, "Too many/too few arguments"), ErrorType::ConfigError => write!(f, "CONFIG"), ErrorType::DBError => write!(f, "DATABASE"), + ErrorType::ModError => write!(f, "Mod: {}", self.message), ErrorType::LibToml => write!(f, "TOML"), ErrorType::LibSql => write!(f, "SQL"), ErrorType::LibReq => write!(f, "REQWEST"), + ErrorType::LibChrono => write!(f, "Chrono error: {}", self.message), ErrorType::IoError => write!(f, "IO"), ErrorType::Other => write!(f, "OTHER") } @@ -68,6 +72,12 @@ impl From for MLError { } } +impl From for MLError { + fn from(error: chrono::ParseError) -> Self { + Self { etype: ErrorType::LibChrono, message: error.to_string() } + } +} + impl From for MLError { fn from(error: std::io::Error) -> Self { Self { etype: ErrorType::IoError, message: error.to_string() } diff --git a/src/files.rs b/src/files.rs index 998ed32..14e5636 100644 --- a/src/files.rs +++ b/src/files.rs @@ -85,12 +85,12 @@ pub fn get_file_path(list: List, versionid: String) -> MLE { Ok(filename.to_owned()) } -pub fn get_downloaded_versions(list: List) -> Result, Box> { +pub fn get_downloaded_versions(list: List) -> MLE> { let mut versions: HashMap = HashMap::new(); for file in read_dir(&list.download_folder)? { let path = file?.path(); - if path.is_file() && path.extension().ok_or("BAH")? == "jar" { - let pathstr = path.to_str().ok_or("BAH")?; + if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { + let pathstr = path.to_str().ok_or("BAH").unwrap(); let namesplit: Vec<&str> = pathstr.split('.').collect(); versions.insert(String::from(namesplit[namesplit.len() - 3]), String::from(namesplit[namesplit.len() - 2])); } diff --git a/src/input.rs b/src/input.rs index 4e59c50..be24660 100644 --- a/src/input.rs +++ b/src/input.rs @@ -7,6 +7,10 @@ pub struct Input { pub mod_id: Option, pub mod_version: Option, pub set_version: bool, + pub all_lists: bool, + pub clean: bool, + pub direct_download: bool, + pub delete_old: bool, pub list: Option, pub list_options: Option, pub list_id: Option, @@ -24,6 +28,7 @@ pub enum Cmd { Update, Download, Io, + Version, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -59,6 +64,10 @@ impl Input { let mut mod_id: Option = None; let mut mod_version: Option = None; let mut set_version = false; + let mut all_lists = false; + let mut clean = false; + let mut direct_download = true; + let mut delete_old = false; let mut list: Option = None; let mut list_options: Option = None; let mut list_id: Option = None; @@ -71,7 +80,9 @@ impl Input { for arg in args { let arg_split: Vec<&str> = arg.trim().split(" ").collect(); match arg_split[0] { - "v" | "version" => { show_version(); }, + "v" | "version" => { + command = Some(Cmd::Version); + }, "d" | "download" => { command = Some(Cmd::Download); }, @@ -81,25 +92,39 @@ impl Input { "ma" => { command = Some(Cmd::Mod); mod_options = Some(ModOptions::Add); - if arg_split.len() != 1 { + if arg_split.len() == 2 { mod_id = Some(String::from(arg_split[1])); } }, + "mv" => { + command = Some(Cmd::Mod); + mod_options = Some(ModOptions::Add); + if arg_split.len() == 2 { + mod_version = Some(String::from(arg_split[1])); + }; + }, "mr" => { command = Some(Cmd::Mod); mod_options = Some(ModOptions::Remove); - if arg_split.len() != 1 { + if arg_split.len() == 2 { mod_id = Some(String::from(arg_split[1])); } }, - "mv" => { - if arg_split.len() != 1 { - mod_version = Some(String::from(arg_split[1])); - }; - }, - "set-version" => { + "set_version" => { set_version = true; }, + "all_lists" => { + all_lists = true; + }, + "clean" => { + clean = true; + }, + "direct-download" => { + direct_download = true; + }, + "delete_old" => { + delete_old = true; + }, "l" => { list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); } @@ -111,7 +136,10 @@ impl Input { "lr" => { command = Some(Cmd::List); list_options = Some(ListOptions::Remove); - list_id = Some(String::from(arg_split[1])); + if arg_split.len() == 2 { + list_id = Some(String::from(arg_split[1])); + list = Some(lists_get(config.clone(), list_id.clone().unwrap())?) + } }, "lc" => { command = Some(Cmd::List); @@ -138,7 +166,7 @@ impl Input { "f" => { file = Some(String::from(arg_split[1])); }, - _ => return Err(MLError::new(ErrorType::ArgumentError, "UnknownArgument")), + _ => return Err(MLError::new(ErrorType::ArgumentError, format!("Unknown Argument ({})", arg_split[0]).as_str())), } } @@ -148,6 +176,10 @@ impl Input { mod_id, mod_version, set_version, + all_lists, + clean, + direct_download, + delete_old, list, list_options, list_id, @@ -160,47 +192,32 @@ impl Input { } } -fn show_version() { - match std::env::var("DEV") { - Ok(dev) => { - let devint = dev.parse::().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")), - } - std::process::exit(0); -} - pub async fn get_input(config: Cfg, args: Vec) -> MLE { let input = Input::from(config.clone(), args)?; - + + if input.command.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No command specified")); }; + match input.clone().command.unwrap() { Cmd::Mod => check_mod(input, config), Cmd::List => check_list(input), - Cmd::Update => check_update(input), - Cmd::Download => check_download(input), - Cmd::Io => check_io(input), + _ => Ok(input), } } //Move checks to commands? translate to variables there? fn check_mod(mut input: Input, config: Cfg) -> MLE { if input.mod_options.is_none() { - return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ARGUMENT")); + return Err(MLError::new(ErrorType::ArgumentError, "No mod option")); }; match input.clone().mod_options.unwrap() { //Check for MV if no mod-id on both ModOptions::Add => { - if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; - if input.list_id.is_none() { println!("NOLIST"); input.list = Some(get_current_list(config.clone())?); }; + if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; + if input.list_id.is_none() { input.list = Some(get_current_list(config.clone())?); }; Ok(input) }, ModOptions::Remove => { - if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID_MODVERSION")); }; + if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; Ok(input) }, } @@ -212,9 +229,13 @@ fn check_list(mut input: Input) -> MLE { }; match input.clone().list_options.unwrap() { ListOptions::Add => { - if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_ID")); }; - if input.list_mcversion.is_none() { /*TODO Get latest version */ input.list_mcversion = Some(String::from("1.19.3")) }; - if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "LISTS_NO_MODLOADER")); }; + if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; + if input.list_mcversion.is_none() { + println!("No Minecraft Version specified, defaulting to latest release"); + //TODO Get latest version + input.list_mcversion = Some(String::from("1.19.3")); + }; + if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); }; if input.directory.is_none() { input.directory = Some(format!("./downloads/{}", input.clone().list_id.expect("earlier if failed"))) }; Ok(input) }, @@ -230,18 +251,6 @@ fn check_list(mut input: Input) -> MLE { } } -fn check_update(input: Input) -> MLE { - Ok(input) -} - -fn check_download(input: Input) -> MLE { - Ok(input) -} - -fn check_io(input: Input) -> MLE { - Ok(input) -} - #[test] fn input_from() { let config = Cfg::init("modlist.toml").unwrap(); @@ -253,6 +262,10 @@ fn input_from() { mod_id: None, mod_version: None, set_version: false, + all_lists: false, + clean: false, + direct_download: false, + delete_old: false, list: None, list_options: Some(ListOptions::Add), list_id: Some(String::from("test")), @@ -277,6 +290,10 @@ async fn get_input_test() { mod_id: Some(String::from("test")), mod_version: None, set_version: false, + all_lists: false, + clean: false, + direct_download: false, + delete_old: false, list: Some(lists_get(config.clone(), String::from("one")).unwrap()), list_options: None, list_id: None, diff --git a/src/lib.rs b/src/lib.rs index ef97a53..eb845d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,14 @@ -//pub mod apis; +pub mod apis; pub mod config; pub mod commands; pub mod input; pub mod db; pub mod error; -//pub mod files; +pub mod files; use std::path::Path; -//pub use apis::*; +pub use apis::*; pub use commands::*; use error::{MLE, ErrorType, MLError}; diff --git a/src/main.rs b/src/main.rs index 39e46e8..10980fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -use std::env; +use std::{env, process}; -use modlist::{config::Cfg, input::get_input}; +use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io}; #[tokio::main] async fn main() { @@ -11,10 +11,49 @@ async fn main() { args.pop(); args.reverse(); - match get_input(config, args).await { - Ok(..) => (), + let input = match get_input(config.clone(), args).await { + Ok(i) => i, Err(e) => { println!("{}", e); + process::exit(1); } }; + + dbg!(&input); + + match input.clone().command.unwrap() { + Cmd::Mod => { + Ok(()) + }, + 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(()) + }, + }.unwrap() +} + +fn show_version() { + match std::env::var("DEV") { + Ok(dev) => { + let devint = dev.parse::().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")), + } } -- cgit v1.2.3