From 0c154966b2b75aa1250bcf32bfd0b9d0ab4864cf Mon Sep 17 00:00:00 2001 From: Michal Date: Thu, 21 Jul 2022 14:30:52 +0100 Subject: [PATCH] Implemented new Clean operation --- src/args.rs | 4 ++++ src/main.rs | 1 + src/operations/clean.rs | 16 ++++++++++++++++ src/operations/mod.rs | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 src/operations/clean.rs diff --git a/src/args.rs b/src/args.rs index 7fc7cbb..4eb3eb4 100644 --- a/src/args.rs +++ b/src/args.rs @@ -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 { diff --git a/src/main.rs b/src/main.rs index c3c0583..47e8879 100755 --- a/src/main.rs +++ b/src/main.rs @@ -69,5 +69,6 @@ fn main() { repository::generate(); } Operation::Config => operations::config(), + Operation::Clean => operations::clean(), } } diff --git a/src/operations/clean.rs b/src/operations/clean.rs new file mode 100644 index 0000000..68f21e7 --- /dev/null +++ b/src/operations/clean.rs @@ -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::>(); + + // 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(); + } +} \ No newline at end of file diff --git a/src/operations/mod.rs b/src/operations/mod.rs index 686ef4d..bbba783 100644 --- a/src/operations/mod.rs +++ b/src/operations/mod.rs @@ -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;