Consistent formatting for lists

main
Michal 2 years ago
parent 60ed5883a4
commit 8785d687ee

@ -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::<Vec<String>>()
.join("\n ")
);
}

@ -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<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![];
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()
);
}
}
}

Loading…
Cancel
Save