From 96cc5257de09682df345e768dc2a91303f9b36c9 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 3 Nov 2022 21:34:04 +0100 Subject: added update beginnings; init of tests --- src/commands/update.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/commands/update.rs (limited to 'src/commands/update.rs') diff --git a/src/commands/update.rs b/src/commands/update.rs new file mode 100644 index 0000000..14c37ec --- /dev/null +++ b/src/commands/update.rs @@ -0,0 +1,40 @@ +use std::io::{Error, ErrorKind}; + +use crate::{config::Cfg, modrinth::projects, get_current_list, db::{get_mods_from_list, get_versions}}; + +pub async fn update(config: Cfg) -> Result<(), Box> { + + let current_list = get_current_list(config.clone())?; + + let mods = get_mods_from_list(config.clone(), current_list)?; + + let mut projects = projects(String::from(&config.apis.modrinth), mods.clone()).await; + + let mut versions = get_versions(config, mods)?; + + projects.sort_by_key(|p| p.id.clone()); + + versions.sort_by_key(|v| v.mod_id.clone()); + + let mut update_stack: Vec = vec![]; + + for (index, project) in projects.iter().enumerate() { + + let cmp_version = &versions[index]; + + let p_id = &project.id; + let v_id = &cmp_version.mod_id; + + if p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "COMPARE_SORTING_ERR"))); }; + println!("{}:{}", p_id, v_id); + + if project.versions.join("|") != cmp_version.versions { + update_stack.push(String::from(&project.id)); + }; + }; + + //TODO UPDATE + dbg!(update_stack); + + Ok(()) +} -- cgit v1.2.3