From b125dfd03084fff47ab8e90d002c6699b762d998 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 1 Nov 2022 23:00:45 +0100 Subject: added list stuff + beginnings of mods --- src/commands/add.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/commands/add.rs') 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 @@ use std::io::{Error, ErrorKind}; -use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader}; +use crate::{modrinth::{project, versions}, config::Cfg, db::insert_mod, Modloader, input::Input}; -pub async fn add(config: Cfg, mc_mod: String) -> Result<(), Box> { - println!("Adding"); +pub async fn modification(config: Cfg, args: Option>) -> Result<(), Box> { - let project = project(String::from(&config.apis.modrinth), &mc_mod).await; + if args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))) } + + let arguments = Input::from(args.unwrap().join(" "))?; + + if arguments.args.is_none() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; + + match arguments.command.as_str() { + "add" => { + add(config, arguments.args.unwrap()).await + }, + _ => Err(Box::new(Error::new(ErrorKind::InvalidInput, "UNKNOWN_SUBCOMMAND"))) + } +} + +pub async fn add(config: Cfg, args: Vec) -> Result<(), Box> { + + if args.len() < 1 { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; + + let project = project(String::from(&config.apis.modrinth), &args[0]).await; dbg!(&project); @@ -14,7 +31,8 @@ pub async fn add(config: Cfg, mc_mod: String) -> Result<(), Box { Err(Box::new(err)) }, Ok(()) => Ok(()), -- cgit v1.2.3