summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/download.rs18
-rw-r--r--src/commands/modification.rs39
-rw-r--r--src/commands/update.rs12
-rw-r--r--src/db.rs4
-rw-r--r--src/main.rs36
5 files changed, 77 insertions, 32 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs
index 1a8eb8f..ebfb4eb 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -1,6 +1,6 @@
1use crate::{config::Cfg, get_current_list, List}; 1use crate::{config::Cfg, List};
2use crate::{ 2use crate::{
3 db::{lists_get, lists_get_all_ids, userlist_get_all_current_versions_with_mods}, 3 db::userlist_get_all_current_versions_with_mods,
4 error::{ErrorType, MLError, MLE}, 4 error::{ErrorType, MLError, MLE},
5 files::{ 5 files::{
6 clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions, 6 clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions,
@@ -8,20 +8,10 @@ use crate::{
8 modrinth::get_raw_versions, 8 modrinth::get_raw_versions,
9}; 9};
10 10
11pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: bool) -> MLE<()> { 11pub async fn download(config: Cfg, liststack: Vec<List>, clean: bool, delete_old: bool) -> MLE<()> {
12 let mut liststack: Vec<List> = vec![];
13 if all_lists {
14 let list_ids = lists_get_all_ids(config.clone())?;
15 for id in list_ids {
16 liststack.push(lists_get(config.clone(), id)?);
17 }
18 } else {
19 let current = get_current_list(config.clone())?;
20 println!("Downloading current versions of mods in {}", current.id);
21 liststack.push(current)
22 }
23 12
24 for current_list in liststack { 13 for current_list in liststack {
14 println!("Downloading current versions of mods in {}", current_list.id);
25 let downloaded_versions = get_downloaded_versions(current_list.clone())?; 15 let downloaded_versions = get_downloaded_versions(current_list.clone())?;
26 // println!("To download: {:#?}", downloaded_versions); 16 // println!("To download: {:#?}", downloaded_versions);
27 let current_version_ids = match userlist_get_all_current_versions_with_mods( 17 let current_version_ids = match userlist_get_all_current_versions_with_mods(
diff --git a/src/commands/modification.rs b/src/commands/modification.rs
index 67cde0b..216a06e 100644
--- a/src/commands/modification.rs
+++ b/src/commands/modification.rs
@@ -1,8 +1,10 @@
1use std::io::Write;
2
1use crate::{ 3use crate::{
2 config::Cfg, 4 config::Cfg,
3 db::{ 5 db::{
4 lists_get_all_ids, mods_get_id, mods_insert, mods_remove, userlist_get_all_ids, 6 lists_get_all_ids, mods_get_id, mods_insert, mods_remove, userlist_get_all_ids,
5 userlist_get_current_version, userlist_insert, userlist_remove, 7 userlist_get_current_version, userlist_insert, userlist_remove, mods_get_info,
6 }, 8 },
7 error::{ErrorType, MLError, MLE}, 9 error::{ErrorType, MLError, MLE},
8 files::{delete_version, download_versions}, 10 files::{delete_version, download_versions},
@@ -248,17 +250,47 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<String>) -> MLE<Vec<ProjectInfo>
248pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { 250pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> {
249 let mod_id = mods_get_id(&config.data, id)?; 251 let mod_id = mods_get_id(&config.data, id)?;
250 252
253 println!("Remove mod {} from {}", mods_get_info(config.clone(), &mod_id)?.title, list.id);
251 let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; 254 let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?;
252 255
256 print!(" └Remove from list");
257 //Force flush of stdout, else print! doesn't print instantly
258 std::io::stdout().flush()?;
253 userlist_remove(config.clone(), &list.id, &mod_id)?; 259 userlist_remove(config.clone(), &list.id, &mod_id)?;
254 delete_version(list, version)?; 260 println!(" ✓");
261
262 print!(" └Delete file");
263 //Force flush of stdout, else print! doesn't print instantly
264 std::io::stdout().flush()?;
265 match delete_version(list, version) {
266 Ok(_) => (),
267 Err(err) => {
268 if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" {
269 return Err(err);
270 };
271 ()
272 },
273 };
274 println!(" ✓");
255 275
276 print!(" └Clean main db table");
277 //Force flush of stdout, else print! doesn't print instantly
278 std::io::stdout().flush()?;
256 let list_ids = lists_get_all_ids(config.clone())?; 279 let list_ids = lists_get_all_ids(config.clone())?;
257 280
258 // Remove mod from main list if not used elsewhere 281 // Remove mod from main list if not used elsewhere
259 let mut mod_used = false; 282 let mut mod_used = false;
260 for id in list_ids { 283 for id in list_ids {
261 let mods = userlist_get_all_ids(config.clone(), id)?; 284 let mods = match userlist_get_all_ids(config.clone(), id) {
285 Ok(m) => m,
286 Err(err) => {
287 if err.to_string() == "Database: NO_MODS_USERLIST" {
288 println!(" ✓");
289 return Ok(());
290 };
291 return Err(err)
292 }
293 };
262 if mods.contains(&mod_id) { 294 if mods.contains(&mod_id) {
263 mod_used = true; 295 mod_used = true;
264 break; 296 break;
@@ -268,6 +300,7 @@ pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> {
268 if !mod_used { 300 if !mod_used {
269 mods_remove(config, mod_id)?; 301 mods_remove(config, mod_id)?;
270 }; 302 };
303 println!(" ✓");
271 304
272 Ok(()) 305 Ok(())
273} 306}
diff --git a/src/commands/update.rs b/src/commands/update.rs
index 4bc3ac0..d76ba4b 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -18,19 +18,19 @@ pub async fn update(
18 delete_old: bool, 18 delete_old: bool,
19) -> MLE<()> { 19) -> MLE<()> {
20 for current_list in liststack { 20 for current_list in liststack {
21 println!("Update mods in {}", current_list.id);
21 let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; 22 let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?;
22 23
23 let mut current_versions: Vec<(String, String)> = vec![]; 24 let mut current_versions: Vec<(String, String)> = vec![];
24 25
25 println!(" └Update mods:");
26 let mut updatestack: Vec<Version> = vec![]; 26 let mut updatestack: Vec<Version> = vec![];
27 27
28 for id in mods { 28 for id in mods {
29 let info = mods_get_info(config.clone(), &id)?; 29 let info = mods_get_info(config.clone(), &id)?;
30 println!("\t└{}", info.title); 30 println!(" └{}", info.title);
31 31
32 if userlist_get_set_version(config.clone(), &current_list.id, &id)? { 32 if userlist_get_set_version(config.clone(), &current_list.id, &id)? {
33 println!("\t └Set version, skipping update"); 33 println!(" └Set version, skipping update");
34 continue; 34 continue;
35 } 35 }
36 36
@@ -54,7 +54,7 @@ pub async fn update(
54 Err(e) => { 54 Err(e) => {
55 if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" { 55 if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" {
56 println!( 56 println!(
57 "\t └No new version found for the specified minecraft version" 57 " └No new version found for the specified minecraft version"
58 ); 58 );
59 } else { 59 } else {
60 return Err(e); 60 return Err(e);
@@ -76,10 +76,10 @@ pub async fn update(
76 if !clean { 76 if !clean {
77 for ver in current_versions { 77 for ver in current_versions {
78 if delete_old { 78 if delete_old {
79 println!("\t └Delete version {}", ver.0); 79 println!(" └Delete version {}", ver.0);
80 delete_version(current_list.clone(), ver.0)?; 80 delete_version(current_list.clone(), ver.0)?;
81 } else if ver.0 != "NONE" { 81 } else if ver.0 != "NONE" {
82 println!("\t └Disable version {}", ver.0); 82 println!(" └Disable version {}", ver.0);
83 disable_version(config.clone(), current_list.clone(), ver.0, ver.1)?; 83 disable_version(config.clone(), current_list.clone(), ver.0, ver.1)?;
84 }; 84 };
85 } 85 }
diff --git a/src/db.rs b/src/db.rs
index 6c7e4f8..9ffbfe5 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -35,7 +35,7 @@ pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::
35 } 35 }
36 36
37 match mods.is_empty() { 37 match mods.is_empty() {
38 true => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_MODS"))), 38 true => Err(Box::new(Error::new(ErrorKind::NotFound, "NO_MODS_ALL"))),
39 false => Ok(mods), 39 false => Ok(mods),
40 } 40 }
41} 41}
@@ -234,7 +234,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE<Vec<String>> {
234 } 234 }
235 235
236 match mod_ids.is_empty() { 236 match mod_ids.is_empty() {
237 true => Err(MLError::new(ErrorType::DBError, "NO_MODS")), 237 true => Err(MLError::new(ErrorType::DBError, "NO_MODS_USERLIST")),
238 false => Ok(mod_ids), 238 false => Ok(mod_ids),
239 } 239 }
240} 240}
diff --git a/src/main.rs b/src/main.rs
index 3bc2ba0..2db304b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -44,6 +44,10 @@ enum Commands {
44 /// remove disabled versions 44 /// remove disabled versions
45 #[arg(short, long)] 45 #[arg(short, long)]
46 remove: bool, 46 remove: bool,
47
48 /// optional List selection, else default list will be used
49 #[arg(short, long)]
50 list: Option<String>,
47 }, 51 },
48 Update { 52 Update {
49 /// download all lists 53 /// download all lists
@@ -61,6 +65,10 @@ enum Commands {
61 /// delete disabled versions 65 /// delete disabled versions
62 #[arg(short, long)] 66 #[arg(short, long)]
63 remove: bool, 67 remove: bool,
68
69 /// optional List selection, else default list will be used
70 #[arg(short, long)]
71 list: Option<String>,
64 }, 72 },
65 Import { 73 Import {
66 #[arg(short, long)] 74 #[arg(short, long)]
@@ -180,8 +188,6 @@ async fn main() {
180 mod_add(config, vec![marked_id], listf, download, lock).await 188 mod_add(config, vec![marked_id], listf, download, lock).await
181 } 189 }
182 ModCommands::Remove { id, list } => { 190 ModCommands::Remove { id, list } => {
183 //TODO add output
184 //TODO add success even if no file found
185 let listf = match list { 191 let listf = match list {
186 Some(list) => lists_get(config.clone(), list).unwrap(), 192 Some(list) => lists_get(config.clone(), list).unwrap(),
187 None => lists_get( 193 None => lists_get(
@@ -228,12 +234,12 @@ async fn main() {
228 } => list_version(config, id, version, download, remove).await, 234 } => list_version(config, id, version, download, remove).await,
229 } 235 }
230 } 236 }
231 //TODO a add specific list
232 Commands::Update { 237 Commands::Update {
233 all, 238 all,
234 download, 239 download,
235 clean, 240 clean,
236 remove, 241 remove,
242 list
237 } => { 243 } => {
238 let mut liststack: Vec<List> = vec![]; 244 let mut liststack: Vec<List> = vec![];
239 if all { 245 if all {
@@ -242,14 +248,30 @@ async fn main() {
242 liststack.push(lists_get(config.clone(), id).unwrap()); 248 liststack.push(lists_get(config.clone(), id).unwrap());
243 } 249 }
244 } else { 250 } else {
245 let current = get_current_list(config.clone()).unwrap(); 251 let current = match list {
246 println!("Update list {}:", current.id); 252 Some(l) => lists_get(config.clone(), l).unwrap(),
253 None => get_current_list(config.clone()).unwrap(),
254 };
247 liststack.push(current) 255 liststack.push(current)
248 } 256 }
249 update(config, liststack, clean, download, remove).await 257 update(config, liststack, clean, download, remove).await
250 } 258 }
251 //TODO add specific list 259 Commands::Download { all, clean, remove, list } => {
252 Commands::Download { all, clean, remove } => download(config, all, clean, remove).await, 260 let mut liststack: Vec<List> = vec![];
261 if all {
262 let list_ids = lists_get_all_ids(config.clone()).unwrap();
263 for id in list_ids {
264 liststack.push(lists_get(config.clone(), id).unwrap());
265 }
266 } else {
267 let current = match list {
268 Some(l) => lists_get(config.clone(), l).unwrap(),
269 None => get_current_list(config.clone()).unwrap(),
270 };
271 liststack.push(current)
272 }
273 download(config, liststack, clean, remove).await
274 },
253 Commands::Import { file, download } => { 275 Commands::Import { file, download } => {
254 let filestr: String = match file { 276 let filestr: String = match file {
255 Some(args) => args, 277 Some(args) => args,