summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands/modification.rs4
-rw-r--r--src/commands/update.rs3
-rw-r--r--src/files.rs1
-rw-r--r--src/input.rs51
-rw-r--r--src/main.rs4
5 files changed, 41 insertions, 22 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs
index 6a03b35..c194202 100644
--- a/src/commands/modification.rs
+++ b/src/commands/modification.rs
@@ -20,6 +20,7 @@ async fn add(config: Cfg, input: Input) -> MLE<()> {
20 20
21pub async fn mod_add(config: Cfg, mod_id: Vec<String>, list: List, disable_download: bool) -> MLE<()> { 21pub async fn mod_add(config: Cfg, mod_id: Vec<String>, list: List, disable_download: bool) -> MLE<()> {
22 22
23 //Fix printing (its horrible)
23 println!("Adding mod(s) {:?}", mod_id); 24 println!("Adding mod(s) {:?}", mod_id);
24 let projects = if mod_id.len() == 1 { 25 let projects = if mod_id.len() == 1 {
25 vec![project(String::from(&config.apis.modrinth), &mod_id[0]).await] 26 vec![project(String::from(&config.apis.modrinth), &mod_id[0]).await]
@@ -87,7 +88,8 @@ pub async fn mod_add(config: Cfg, mod_id: Vec<String>, list: List, disable_downl
87} 88}
88 89
89fn remove(config: Cfg, input: Input) -> MLE<()> { 90fn remove(config: Cfg, input: Input) -> MLE<()> {
90 91
92 //TODO inplement deletion by slug or title
91 let mod_id = mods_get_id(config.clone(), input.clone().mod_id.unwrap())?; 93 let mod_id = mods_get_id(config.clone(), input.clone().mod_id.unwrap())?;
92 94
93 let version = userlist_get_current_version(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; 95 let version = userlist_get_current_version(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?;
diff --git a/src/commands/update.rs b/src/commands/update.rs
index f8bdb82..f71f537 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -139,6 +139,7 @@ async fn download_updates_test() {
139 139
140 use crate::{modrinth::{Version, VersionFile, Hash, VersionType}, Modloader, List}; 140 use crate::{modrinth::{Version, VersionFile, Hash, VersionType}, Modloader, List};
141 141
142 let config = Cfg::init("modlist.toml").unwrap();
142 let current_list = List { id: String::from("..."), mc_version: String::from("..."), modloader: Modloader::Forge, download_folder: String::from("./dl") }; 143 let current_list = List { id: String::from("..."), mc_version: String::from("..."), modloader: Modloader::Forge, download_folder: String::from("./dl") };
143 144
144 let versions = vec![Version { 145 let versions = vec![Version {
@@ -171,5 +172,5 @@ async fn download_updates_test() {
171 "fabric".to_string() 172 "fabric".to_string()
172 ] 173 ]
173 }]; 174 }];
174 assert!(download_versions(current_list, versions).await.is_ok()) 175 assert!(download_versions(current_list, config, versions).await.is_ok())
175} 176}
diff --git a/src/files.rs b/src/files.rs
index 0d7dc0a..ecb6e3e 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -11,7 +11,6 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>)
11 println!("Download to directory from: {} ({})", list.id, dl_path); 11 println!("Download to directory from: {} ({})", list.id, dl_path);
12 12
13 for ver in versions { 13 for ver in versions {
14 //TODO get project name instead of projectid from db
15 let project_name = mods_get_name(config.clone(), &ver.project_id)?; 14 let project_name = mods_get_name(config.clone(), &ver.project_id)?;
16 print!("\t({})Download version {}", project_name, ver.id); 15 print!("\t({})Download version {}", project_name, ver.id);
17 std::io::stdout().flush().unwrap(); 16 std::io::stdout().flush().unwrap();
diff --git a/src/input.rs b/src/input.rs
index a41f671..144f22a 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -1,4 +1,4 @@
1use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List}; 1use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}};
2 2
3#[derive(Debug, Clone, PartialEq, Eq)] 3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct Input { 4pub struct Input {
@@ -54,10 +54,8 @@ pub enum IoOptions {
54impl Input { 54impl Input {
55 fn from(config: Cfg, input: Vec<String>) -> MLE<Self> { 55 fn from(config: Cfg, input: Vec<String>) -> MLE<Self> {
56 let input_string = input.join(" "); 56 let input_string = input.join(" ");
57 let mut args: Vec<&str> = input_string.split('-').collect(); 57 let mut args: Vec<&str> = input_string.split(" -").collect();
58 args.reverse(); 58 args[0] = args[0].split_at(1).1;
59 args.pop();
60 args.reverse();
61 59
62 let mut command: Option<Cmd> = None; 60 let mut command: Option<Cmd> = None;
63 61
@@ -95,6 +93,8 @@ impl Input {
95 mod_options = Some(ModOptions::Add); 93 mod_options = Some(ModOptions::Add);
96 if arg_split.len() == 2 { 94 if arg_split.len() == 2 {
97 mod_id = Some(String::from(arg_split[1])); 95 mod_id = Some(String::from(arg_split[1]));
96 } else {
97 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list mod slug or id"));
98 } 98 }
99 }, 99 },
100 "mv" => { 100 "mv" => {
@@ -102,6 +102,8 @@ impl Input {
102 mod_options = Some(ModOptions::Add); 102 mod_options = Some(ModOptions::Add);
103 if arg_split.len() == 2 { 103 if arg_split.len() == 2 {
104 mod_version = Some(String::from(arg_split[1])); 104 mod_version = Some(String::from(arg_split[1]));
105 } else {
106 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a version id"));
105 }; 107 };
106 }, 108 },
107 "mr" => { 109 "mr" => {
@@ -109,7 +111,9 @@ impl Input {
109 mod_options = Some(ModOptions::Remove); 111 mod_options = Some(ModOptions::Remove);
110 if arg_split.len() == 2 { 112 if arg_split.len() == 2 {
111 mod_id = Some(String::from(arg_split[1])); 113 mod_id = Some(String::from(arg_split[1]));
112 } 114 } else {
115 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a mod id"));
116 };
113 }, 117 },
114 "set_version" => { 118 "set_version" => {
115 set_version = true; 119 set_version = true;
@@ -120,7 +124,7 @@ impl Input {
120 "clean" => { 124 "clean" => {
121 clean = true; 125 clean = true;
122 }, 126 },
123 "no-download" => { 127 "no_download" => {
124 direct_download = false; 128 direct_download = false;
125 }, 129 },
126 "delete_old" => { 130 "delete_old" => {
@@ -136,7 +140,11 @@ impl Input {
136 "la" => { 140 "la" => {
137 command = Some(Cmd::List); 141 command = Some(Cmd::List);
138 list_options = Some(ListOptions::Add); 142 list_options = Some(ListOptions::Add);
139 list_id = Some(String::from(arg_split[1])); 143 if arg_split.len() == 2 {
144 list_id = Some(String::from(arg_split[1]));
145 } else {
146 return Err(MLError::new(ErrorType::ArgumentError, "Please give the new list an id"));
147 }
140 }, 148 },
141 "lr" => { 149 "lr" => {
142 command = Some(Cmd::List); 150 command = Some(Cmd::List);
@@ -163,10 +171,18 @@ impl Input {
163 } 171 }
164 }, 172 },
165 "ml" => { 173 "ml" => {
166 modloader = Some(Modloader::from(arg_split[1])?); 174 if arg_split.len() == 2 {
175 modloader = Some(Modloader::from(arg_split[1])?);
176 } else {
177 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a modloader"));
178 }
167 }, 179 },
168 "dir" => { 180 "dir" => {
169 directory = Some(String::from(arg_split[1])); 181 if arg_split.len() == 2 {
182 directory = Some(String::from(arg_split[1]));
183 } else {
184 return Err(MLError::new(ErrorType::ArgumentError, "Please specify a directory"));
185 }
170 }, 186 },
171 "export" => { 187 "export" => {
172 command = Some(Cmd::Io); 188 command = Some(Cmd::Io);
@@ -212,18 +228,16 @@ pub async fn get_input(config: Cfg, args: Vec<String>) -> MLE<Input> {
212 228
213 match input.clone().command.unwrap() { 229 match input.clone().command.unwrap() {
214 Cmd::Mod => check_mod(input, config), 230 Cmd::Mod => check_mod(input, config),
215 Cmd::List => check_list(input, config), 231 Cmd::List => check_list(input, config).await,
216 _ => Ok(input), 232 _ => Ok(input),
217 } 233 }
218} 234}
219 235
220//Move checks to commands? translate to variables there?
221fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> { 236fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> {
222 if input.mod_options.is_none() { 237 if input.mod_options.is_none() {
223 return Err(MLError::new(ErrorType::ArgumentError, "No mod option")); 238 return Err(MLError::new(ErrorType::ArgumentError, "No mod option"));
224 }; 239 };
225 match input.clone().mod_options.unwrap() { 240 match input.clone().mod_options.unwrap() {
226 //Check for MV if no mod-id on both
227 ModOptions::Add => { 241 ModOptions::Add => {
228 if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; 242 if input.mod_id.is_none() && input.mod_version.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); };
229 if input.list_id.is_none() { input.list = Some(get_current_list(config.clone())?); }; 243 if input.list_id.is_none() { input.list = Some(get_current_list(config.clone())?); };
@@ -236,7 +250,7 @@ fn check_mod(mut input: Input, config: Cfg) -> MLE<Input> {
236 } 250 }
237} 251}
238 252
239fn check_list(mut input: Input, config: Cfg) -> MLE<Input> { 253async fn check_list(mut input: Input, config: Cfg) -> MLE<Input> {
240 if input.list_options.is_none() { 254 if input.list_options.is_none() {
241 return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT")); 255 return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT"));
242 }; 256 };
@@ -245,11 +259,14 @@ fn check_list(mut input: Input, config: Cfg) -> MLE<Input> {
245 if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; 259 if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); };
246 if input.list_mcversion.is_none() { 260 if input.list_mcversion.is_none() {
247 println!("No Minecraft Version specified, defaulting to latest release"); 261 println!("No Minecraft Version specified, defaulting to latest release");
248 //TODO Get latest version 262 input.list_mcversion = Some(get_minecraft_version(config.apis.modrinth, MCVersionType::Release).await);
249 input.list_mcversion = Some(String::from("1.19.3")); 263 };
264 if input.directory.is_none() {
265 let id = input.clone().list_id.unwrap();
266 println!("No download directory specified, defaulting to ./downloads/{}", id);
267 input.directory = Some(format!("./downloads/{}", id))
250 }; 268 };
251 if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); }; 269 if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); };
252 if input.directory.is_none() { input.directory = Some(format!("./downloads/{}", input.clone().list_id.expect("earlier if failed"))) };
253 Ok(input) 270 Ok(input)
254 }, 271 },
255 ListOptions::Remove => { 272 ListOptions::Remove => {
diff --git a/src/main.rs b/src/main.rs
index 2fca691..d177c3e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
1use std::{env, process}; 1use std::{env, process};
2 2
3use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io}; 3use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io, modification};
4 4
5#[tokio::main] 5#[tokio::main]
6async fn main() { 6async fn main() {
@@ -23,7 +23,7 @@ async fn main() {
23 23
24 match input.clone().command.unwrap() { 24 match input.clone().command.unwrap() {
25 Cmd::Mod => { 25 Cmd::Mod => {
26 Ok(()) 26 modification(config, input).await
27 }, 27 },
28 Cmd::List => { 28 Cmd::List => {
29 list(config, input).await 29 list(config, input).await