From ad356bf4d1ed7f867631ab6d424ea4117746bd86 Mon Sep 17 00:00:00 2001 From: Luca Visentin Date: Sun, 18 Feb 2024 18:26:23 +0100 Subject: [PATCH] feat: add the --yes flag to 'data clean' --- README.md | 6 ++++++ docs/tutorial.md | 4 ++++ src/commands/data.rs | 23 ++++++++++++++++------- src/lib.rs | 6 +++++- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d5bcd7b..a4adf70 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,12 @@ Kerblam! then allows you to: To transform a project to a Kerblam! project just make the kerblam.toml file yourself. To learn how, look at the section below. +
+ +[✨ See usage examples of Kerblam! ✨](https://github.com/MrHedmad/kerblam-examples) + +
+ # Overview Kerblam! has the following commands: - :magic_wand: `kerblam new` can be used to create a new kerblam! diff --git a/docs/tutorial.md b/docs/tutorial.md index 7b1b269..af5def4 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -307,6 +307,10 @@ Kerblam! will consider as "remotely available" files that are present in the > If you want to preserve the empty folders left behind after cleaning, > pass the `--keep-dirs` flag to do just that. +> [!TIP] +> Kerblam! will ask for your confirmation before deleting the files. +> If you're feeling bold, skip it with the `--yes` flag. + ### `kerblam data pack` - Package and export your local data Say that you wish to send all your data folder to a colleague for inspection. You can `tar -czvf exported_data.tar.gz ./data/` and send your whole data folder, diff --git a/src/commands/data.rs b/src/commands/data.rs index 62d473d..552f5f3 100644 --- a/src/commands/data.rs +++ b/src/commands/data.rs @@ -374,7 +374,12 @@ fn delete_files(files: Vec) -> Result<()> { Ok(()) } -pub fn clean_data(config: KerblamTomlOptions, keep_remote: bool, keep_dirs: bool) -> Result<()> { +pub fn clean_data( + config: KerblamTomlOptions, + keep_remote: bool, + keep_dirs: bool, + skip_confirm: bool, +) -> Result<()> { let cleanable_files = config.volatile_files(); let remote_files: Vec = config .remote_files() @@ -406,12 +411,16 @@ pub fn clean_data(config: KerblamTomlOptions, keep_remote: bool, keep_dirs: bool .sum::() ); - match ask_for::(question.as_str()) { - YesNo::Yes => delete_files(cleanable_files.clone())?, - YesNo::No => { - bail!("Aborted!"); - } - }; + if skip_confirm { + delete_files(cleanable_files.clone())? + } else { + match ask_for::(question.as_str()) { + YesNo::Yes => delete_files(cleanable_files.clone())?, + YesNo::No => { + bail!("Aborted!"); + } + }; + } } // After we cleanup the files, we can cleanup the directories diff --git a/src/lib.rs b/src/lib.rs index 2c538ce..6ac436d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,6 +88,9 @@ enum DataCommands { #[arg(long, short('d'), action)] /// Do not delete locally present directories. keep_dirs: bool, + #[arg(long, short, action)] + /// Do not ask for any confirmation. + yes: bool, }, // Pack local data for export to others Pack { @@ -154,7 +157,8 @@ where Some(DataCommands::Clean { keep_remote, keep_dirs, - }) => clean_data(config, keep_remote, keep_dirs)?, + yes, + }) => clean_data(config, keep_remote, keep_dirs, yes)?, Some(DataCommands::Pack { output_path: path }) => package_data_to_archive( config, path.unwrap_or(here.join("data/data_export.tar.gz")),