Implemented new Clean operation

main
Michal 2 years ago
parent cbd598a084
commit 0c154966b2
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -42,6 +42,10 @@ pub enum Operation {
#[clap(name = "clone", aliases = & ["init", "i", "c"])] #[clap(name = "clone", aliases = & ["init", "i", "c"])]
Clone, 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 /// Pulls in git repositories from mlc.toml branching from current directory
#[clap(name = "pull", aliases = & ["u"])] #[clap(name = "pull", aliases = & ["u"])]
Pull { Pull {

@ -69,5 +69,6 @@ fn main() {
repository::generate(); repository::generate();
} }
Operation::Config => operations::config(), 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 clone::*;
pub use config::*; pub use config::*;
pub use pull::*; pub use pull::*;
pub use clean::*;
mod build; mod build;
mod clone; mod clone;
mod config; mod config;
mod pull; mod pull;
mod clean;

Loading…
Cancel
Save