summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-09 20:34:09 +0200
committerfxqnlr <[email protected]>2023-05-09 20:34:09 +0200
commit9063a041f6b2e72f6e4a861c77ac16065dd5378b (patch)
tree03d34dfe9ff05de2dd74d3afe1cde87712f1b59a /src/commands
parent0c7ba29d3e17c47e5fc9cffe78c28a0019d453b7 (diff)
downloadmodlist-9063a041f6b2e72f6e4a861c77ac16065dd5378b.tar
modlist-9063a041f6b2e72f6e4a861c77ac16065dd5378b.tar.gz
modlist-9063a041f6b2e72f6e4a861c77ac16065dd5378b.zip
add list toggles to update and download;
add mod remove output and fix errors
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/download.rs18
-rw-r--r--src/commands/modification.rs39
-rw-r--r--src/commands/update.rs12
3 files changed, 46 insertions, 23 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 }