aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/cli.rs14
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs2
3 files changed, 16 insertions, 2 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"),
diff --git a/src/lib.rs b/src/lib.rs
index 8c6c768..1c60e70 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,6 +19,8 @@ extern crate diesel;
extern crate serde_derive;
#[macro_use]
extern crate async_trait;
+#[macro_use]
+extern crate simple_error;
pub mod cli;
pub mod config;
diff --git a/src/main.rs b/src/main.rs
index 97ecf4a..8182fff 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,7 +19,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.start()?;
// Execution
- Cli::execute(matches).await;
+ Cli::execute(matches).await.unwrap();
Ok(())
}