summaryrefslogtreecommitdiff
path: root/src/commands/add.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/add.rs')
-rw-r--r--src/commands/add.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/commands/add.rs b/src/commands/add.rs
index 67f63de..ed4a6d8 100644
--- a/src/commands/add.rs
+++ b/src/commands/add.rs
@@ -1,11 +1,28 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2 2
3use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader}; 3use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader, input::Input};
4 4
5pub async fn add(config: Cfg, mc_mod: String) -> Result<(), Box<dyn std::error::Error>> { 5pub async fn modification(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> {
6 println!("Adding");
7 6
8 let project = project(String::from(&config.apis.modrinth), &mc_mod).await; 7 if args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))) }
8
9 let arguments = Input::from(args.unwrap().join(" "))?;
10
11 if arguments.args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); };
12
13 match arguments.command.as_str() {
14 "add" => {
15 add(config, arguments.args.unwrap()).await
16 },
17 _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_SUBCOMMAND")))
18 }
19}
20
21pub async fn add(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
22
23 if args.len() < 1 { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); };
24
25 let project = project(String::from(&config.apis.modrinth), &args[0]).await;
9 26
10 dbg!(&project); 27 dbg!(&project);
11 28
@@ -14,7 +31,8 @@ pub async fn add(config: Cfg, mc_mod: String) -> Result<(), Box<dyn std::error::
14 if project.versions.is_empty() { panic!("This should never happen"); }; 31 if project.versions.is_empty() { panic!("This should never happen"); };
15 32
16 let current_version = get_current(config, String::from(&project.id)).await?; 33 let current_version = get_current(config, String::from(&project.id)).await?;
17 34
35 //add to current list and mod table
18 match insert_mod(project.id, project.title, current_version, project.versions, loader, String::from("1.19.2")) { 36 match insert_mod(project.id, project.title, current_version, project.versions, loader, String::from("1.19.2")) {
19 Err(err) => { Err(Box::new(err)) }, 37 Err(err) => { Err(Box::new(err)) },
20 Ok(()) => Ok(()), 38 Ok(()) => Ok(()),