Consistent formatting for lists

main
Michal 2 years ago
parent 09e7e544dc
commit f6c878d061
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -13,7 +13,15 @@ pub fn clean(verbose: bool) {
dirs.retain(|x| *x != "./mlc.toml"); dirs.retain(|x| *x != "./mlc.toml");
dirs.retain(|x| *x != "./.git"); dirs.retain(|x| *x != "./.git");
log!(verbose, "Paths with mlc.toml excluded: {:?}", dirs); log!(verbose, "Paths with mlc.toml excluded: {:?}", dirs);
for dir in dirs { for dir in &dirs {
std::fs::remove_dir_all(dir).unwrap(); std::fs::remove_dir_all(dir).unwrap();
} }
info!(
"Reset complete, dirs removed: \n \
{}",
dirs.iter()
.map(|x| x.replace("./", ""))
.collect::<Vec<String>>()
.join("\n ")
);
} }

@ -6,6 +6,8 @@ use crate::info;
use crate::log; use crate::log;
use crate::parse_cfg; use crate::parse_cfg;
use colored::Colorize;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct PackageFile { struct PackageFile {
name: String, name: String,
@ -37,18 +39,19 @@ pub fn prune(verbose: bool) {
} }
log!(verbose, "Files: {:?}", files); log!(verbose, "Files: {:?}", files);
// Split files into Vec<PackageFile>, 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<PackageFile>, 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<PackageFile> = vec![]; let mut packages: Vec<PackageFile> = vec![];
for file in files { for file in files {
// Regex fuckery. Please don't mess with this. // Regex fuckery. Please don't mess with this.
let re = regex::Regex::new(r"^(.+)(-.+-.+)(-.+\..+\..+\.+..+)$").unwrap(); let re = regex::Regex::new(r"^(.+)(-.+-.+)(-.+\..+\..+\.+..+)$").unwrap();
let file = file.to_str().unwrap(); let file = file.to_str().unwrap();
for cap in re.captures_iter(file) { for cap in re.captures_iter(file) {
// Collect regex captures
let name = cap[1].to_string(); let name = cap[1].to_string();
let mut ver = cap[2].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(); let mut ext = cap[3].to_string();
// Strip leading - from ver and ext
ver.remove(0).to_string();
ext.remove(0).to_string(); ext.remove(0).to_string();
let package = PackageFile { name, ver, ext }; let package = PackageFile { name, ver, ext };
log!(verbose, "Package: {:?}", package); log!(verbose, "Package: {:?}", package);
@ -115,7 +118,10 @@ pub fn prune(verbose: bool) {
} else { } else {
info!("Deleted the following packages:"); info!("Deleted the following packages:");
for p in &mut packages_to_delete { for p in &mut packages_to_delete {
info!("{}-{}", p.name.replace("./", ""), p.ver); println!(
"{}",
format!(" {}-{}", p.name.replace("./", ""), p.ver).bold()
);
} }
} }
} }

Loading…
Cancel
Save