summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-11-03 21:34:04 +0100
committerfxqnlr <[email protected]>2022-11-03 21:34:04 +0100
commit96cc5257de09682df345e768dc2a91303f9b36c9 (patch)
treef505d14c581e2bef4cfe222bd1069661bedd22e0 /src/commands/update.rs
parentb125dfd03084fff47ab8e90d002c6699b762d998 (diff)
downloadmodlist-96cc5257de09682df345e768dc2a91303f9b36c9.tar
modlist-96cc5257de09682df345e768dc2a91303f9b36c9.tar.gz
modlist-96cc5257de09682df345e768dc2a91303f9b36c9.zip
added update beginnings; init of tests
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs40
1 files changed, 40 insertions, 0 deletions
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 @@
1use std::io::{Error, ErrorKind};
2
3use crate::{config::Cfg, modrinth::projects, get_current_list, db::{get_mods_from_list, get_versions}};
4
5pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
6
7 let current_list = get_current_list(config.clone())?;
8
9 let mods = get_mods_from_list(config.clone(), current_list)?;
10
11 let mut projects = projects(String::from(&config.apis.modrinth), mods.clone()).await;
12
13 let mut versions = get_versions(config, mods)?;
14
15 projects.sort_by_key(|p| p.id.clone());
16
17 versions.sort_by_key(|v| v.mod_id.clone());
18
19 let mut update_stack: Vec<String> = vec![];
20
21 for (index, project) in projects.iter().enumerate() {
22
23 let cmp_version = &versions[index];
24
25 let p_id = &project.id;
26 let v_id = &cmp_version.mod_id;
27
28 if p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "COMPARE_SORTING_ERR"))); };
29 println!("{}:{}", p_id, v_id);
30
31 if project.versions.join("|") != cmp_version.versions {
32 update_stack.push(String::from(&project.id));
33 };
34 };
35
36 //TODO UPDATE
37 dbg!(update_stack);
38
39 Ok(())
40}