summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/add.rs34
-rw-r--r--src/commands/mod.rs3
2 files changed, 37 insertions, 0 deletions
diff --git a/src/commands/add.rs b/src/commands/add.rs
new file mode 100644
index 0000000..67f63de
--- /dev/null
+++ b/src/commands/add.rs
@@ -0,0 +1,34 @@
1use std::io::{Error, ErrorKind};
2
3use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader};
4
5pub async fn add(config: Cfg, mc_mod: String) -> Result<(), Box<dyn std::error::Error>> {
6 println!("Adding");
7
8 let project = project(String::from(&config.apis.modrinth), &mc_mod).await;
9
10 dbg!(&project);
11
12 let loader = Modloader::Fabric;
13
14 if project.versions.is_empty() { panic!("This should never happen"); };
15
16 let current_version = get_current(config, String::from(&project.id)).await?;
17
18 match insert_mod(project.id, project.title, current_version, project.versions, loader, String::from("1.19.2")) {
19 Err(err) => { Err(Box::new(err)) },
20 Ok(()) => Ok(()),
21 }
22
23}
24
25async fn get_current(config: Cfg, id: String) -> Result<String, Box<dyn std::error::Error>> {
26 let available_versions = versions(config.apis.modrinth, id, Modloader::Fabric, String::from("1.19.2")).await;
27
28 match available_versions.len() {
29 0 => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_VERSIONS_AVAILABLE"))),
30 //TODO compare publish dates
31 1.. => Ok(available_versions[0].id.to_string()),
32 _ => panic!("available_versions should never be negative"),
33 }
34}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
new file mode 100644
index 0000000..0cc183a
--- /dev/null
+++ b/src/commands/mod.rs
@@ -0,0 +1,3 @@
1pub mod add;
2
3pub use add::*;