From 2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Fri, 26 May 2023 17:40:27 +0200 Subject: added full progress? cargo fmt --- src/commands/list.rs | 54 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'src/commands/list.rs') diff --git a/src/commands/list.rs b/src/commands/list.rs index 52f14f2..b0a082d 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,11 +1,13 @@ +use indicatif::{ProgressBar, ProgressStyle}; + use crate::{ config::Cfg, db::{ - config_change_current_list, config_get_current_list, lists_get, lists_insert, lists_remove, - lists_version, lists_get_all_ids, + config_change_current_list, config_get_current_list, lists_get, lists_get_all_ids, + lists_insert, lists_remove, lists_version, }, - error::{MLE, MLError, ErrorType}, - update, Modloader, + error::{ErrorType, MLError, MLE}, + update, Modloader, STYLE_OPERATION, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -28,20 +30,35 @@ pub fn list_add( modloader: &Modloader, directory: &str, ) -> MLE<()> { - lists_insert(config, id, mc_version, modloader, directory) + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!("Create {}", id)); + lists_insert(config, id, mc_version, modloader, directory)?; + p.finish_with_message(format!("Created {}", id)); + Ok(()) } -pub fn list_change(config: &Cfg, id: String) -> MLE<()> { +pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!("Change default list to {}", id)); + if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { return Err(MLError::new(ErrorType::ArgumentError, "List not found")); }; - println!("Change default list to: {}", id); - config_change_current_list(config, id) + config_change_current_list(config, id)?; + + p.finish_with_message(format!("Changed default list to {}", id)); + Ok(()) } -pub fn list_remove(config: &Cfg, id: String) -> MLE<()> { - //TODO add logging - lists_remove(config, id) +pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!("Remove {}", id)); + lists_remove(config, id)?; + p.finish_with_message(format!("Removed {}", id)); + Ok(()) } ///Changing the current lists version and updating it @@ -57,17 +74,20 @@ pub async fn list_version( download: bool, delete: bool, ) -> MLE<()> { - println!( + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!( "Change version for list {} to minecraft version: {}", id, mc_version - ); + )); lists_version(config, id, &mc_version)?; - println!( - "\nCheck for updates for new minecraft version in list {}", - id - ); + p.finish_with_message(format!( + "Changed version for list {} to minecraft version: {}", + id, mc_version + )); + let list = lists_get(config, id)?; update(config, vec![list], true, download, delete).await } -- cgit v1.2.3