diff options
author | fxqnlr <[email protected]> | 2022-11-01 23:00:45 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-01 23:00:45 +0100 |
commit | b125dfd03084fff47ab8e90d002c6699b762d998 (patch) | |
tree | 151677fb5e88105c06e1072c2fa309f55afaba36 /src/commands/add.rs | |
parent | d38f09a247b8bf1ed328c342f84b74581905317d (diff) | |
download | modlist-b125dfd03084fff47ab8e90d002c6699b762d998.tar modlist-b125dfd03084fff47ab8e90d002c6699b762d998.tar.gz modlist-b125dfd03084fff47ab8e90d002c6699b762d998.zip |
added list stuff + beginnings of mods
Diffstat (limited to 'src/commands/add.rs')
-rw-r--r-- | src/commands/add.rs | 28 |
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 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader}; | 3 | use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader, input::Input}; |
4 | 4 | ||
5 | pub async fn add(config: Cfg, mc_mod: String) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub 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 | |||
21 | pub 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(()), |