Implemented new Clean operation

main
Michal 2 years ago
parent 6e420d7426
commit f0a7012b50

@ -42,6 +42,10 @@ pub enum Operation {
#[clap(name = "clone", aliases = & ["init", "i", "c"])]
Clone,
/// Removes everything in directory except for mlc.toml
#[clap(name = "clean", aliases = & ["clean", "cl", "reset"])]
Clean,
/// Pulls in git repositories from mlc.toml branching from current directory
#[clap(name = "pull", aliases = & ["u"])]
Pull {

@ -69,5 +69,6 @@ fn main() {
repository::generate();
}
Operation::Config => operations::config(),
Operation::Clean => operations::clean(),
}
}

@ -0,0 +1,16 @@
use crate::info;
pub fn clean() {
info!("Resetting mlc repo, deleting all directories");
// Get a vec of all files/dirs in the current directory
let dir_paths = std::fs::read_dir("./").unwrap();
let mut dirs = dir_paths
.map(|x| x.unwrap().path().display().to_string())
.collect::<Vec<String>>();
// Remove all files/dirs in the current directory, excluding ./mlc.toml
dirs.retain(|x| *x != "./mlc.toml");
for dir in dirs {
std::fs::remove_dir_all(dir).unwrap();
}
}

@ -2,8 +2,10 @@ pub use build::*;
pub use clone::*;
pub use config::*;
pub use pull::*;
pub use clean::*;
mod build;
mod clone;
mod config;
mod pull;
mod clean;

Loading…
Cancel
Save