aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-16 16:24:17 +0000
committerFuwn <[email protected]>2021-05-16 16:24:17 +0000
commitaa5c97d75077a79d6f9f0e46c84697e754e7b9b7 (patch)
tree1b2131eb45cfa54f7dec79c23c1fbd7a5a8b098b /src/cli.rs
parentrefactor(subs): remove two second delay before prompt initiailization (diff)
downloadwhirl-aa5c97d75077a79d6f9f0e46c84697e754e7b9b7.tar.xz
whirl-aa5c97d75077a79d6f9f0e46c84697e754e7b9b7.zip
feat(cli): `clean` subcommand
The `clean` subcommand deletes files and directories which are not necessary for Whirl to function.
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/cli.rs b/src/cli.rs
index e6235ec..f6e80a0 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -15,7 +15,7 @@ impl Cli {
matches
}
- pub async fn execute(matches: ArgMatches<'_>) {
+ pub async fn execute(matches: ArgMatches<'_>) -> Result<(), Box<dyn std::error::Error>> {
if Config::get().whirlsplash.log.test {
error!("error");
warn!("warn");
@@ -43,7 +43,17 @@ impl Cli {
Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Fish, ".");
}
debug!("generated shell completions");
+ } else if matches.is_present("clean") {
+ let cleanable_directories = vec!["./log"];
+ for dir in cleanable_directories {
+ println!("cleaning directory '{}'", dir);
+ if let Err(e) = std::fs::remove_dir_all(dir) {
+ bail!("error delete directory '{}': {}", dir, e);
+ }
+ }
}
+
+ Ok(())
}
fn cli<'a, 'b>() -> App<'a, 'b> {
@@ -67,6 +77,8 @@ impl Cli {
SubCommand::with_name("zsh"),
SubCommand::with_name("fish"),
]),
+ SubCommand::with_name("clean")
+ .about("Delete Whirl generated files/ directories which are NOT critical. E.g., logs/"),
])
.args(&[
Arg::with_name("debug").short("d").long("debug"),