From 8785d687eea38fcd77668cf5d2a269537a38f1dd Mon Sep 17 00:00:00 2001 From: Michal Date: Sun, 24 Jul 2022 17:16:24 +0100 Subject: [PATCH] Consistent formatting for lists --- src/operations/clean.rs | 10 +++++++++- src/operations/prune.rs | 14 ++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/operations/clean.rs b/src/operations/clean.rs index 1c9a65d..5a463dc 100644 --- a/src/operations/clean.rs +++ b/src/operations/clean.rs @@ -13,7 +13,15 @@ pub fn clean(verbose: bool) { dirs.retain(|x| *x != "./mlc.toml"); dirs.retain(|x| *x != "./.git"); log!(verbose, "Paths with mlc.toml excluded: {:?}", dirs); - for dir in dirs { + for dir in &dirs { std::fs::remove_dir_all(dir).unwrap(); } + info!( + "Reset complete, dirs removed: \n \ + {}", + dirs.iter() + .map(|x| x.replace("./", "")) + .collect::>() + .join("\n ") + ); } diff --git a/src/operations/prune.rs b/src/operations/prune.rs index 7c83f75..cc17e04 100644 --- a/src/operations/prune.rs +++ b/src/operations/prune.rs @@ -6,6 +6,8 @@ use crate::info; use crate::log; use crate::parse_cfg; +use colored::Colorize; + #[derive(Debug, Clone)] struct PackageFile { name: String, @@ -37,18 +39,19 @@ pub fn prune(verbose: bool) { } log!(verbose, "Files: {:?}", files); - // Split files into Vec, turning name-1.0.0-1-x86_64.tar.gz into PackageFile { name: "name", ver: "1.0.0-1", ext: "x86_64.tar.gz" } + // Split files into Vec, turning package-name-1.0.0-1-x86_64.tar.gz into PackageFile { name: "package-name", ver: "1.0.0-1", ext: "x86_64.tar.gz" } let mut packages: Vec = vec![]; for file in files { // Regex fuckery. Please don't mess with this. let re = regex::Regex::new(r"^(.+)(-.+-.+)(-.+\..+\..+\.+..+)$").unwrap(); let file = file.to_str().unwrap(); for cap in re.captures_iter(file) { + // Collect regex captures let name = cap[1].to_string(); let mut ver = cap[2].to_string(); - // Remove the leading "-" from the version and ext strings - ver.remove(0).to_string(); let mut ext = cap[3].to_string(); + // Strip leading - from ver and ext + ver.remove(0).to_string(); ext.remove(0).to_string(); let package = PackageFile { name, ver, ext }; log!(verbose, "Package: {:?}", package); @@ -115,7 +118,10 @@ pub fn prune(verbose: bool) { } else { info!("Deleted the following packages:"); for p in &mut packages_to_delete { - info!("{}-{}", p.name.replace("./", ""), p.ver); + println!( + "{}", + format!(" {}-{}", p.name.replace("./", ""), p.ver).bold() + ); } } }