diff --git a/src/main.rs b/src/main.rs index acc3c01b8238c804d49cde0493ff632a321b6b40..e60a4639950a51ee75f7eab9a3d7bc8bd749a512 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,9 @@ use clap::{Args, Parser, Subcommand}; mod checkout; mod commit; mod create_hooks; +mod diff; mod init; mod list; -mod diff; - #[derive(Debug, Parser)] #[clap(name = "gbl")] @@ -47,8 +46,11 @@ enum Commands { " )] CreateHooks(CreateHooks), + /// Remove the post-checkout and the post-commit hooks + #[clap(name = "delete-hooks", alias = "dh")] + DeleteHooks, /// Show differences between two commits of the `results` folder - Diff(Diff) + Diff(Diff), } #[derive(Debug, Args)] @@ -75,8 +77,12 @@ struct Commit { /// The compression used to save the results folder (no, lz4, zstd, zlib or lzma) #[clap(short, long, default_value = "lz4")] compression: String, + /// Use this flag to update the content of the current commit archive if it has changed #[clap(takes_value = false, short, long)] update: bool, + /// Use this flag to revert your results folder like it was before for this commit + #[clap(takes_value = false, short, long)] + revert: bool, } #[derive(Debug, Args)] @@ -123,14 +129,13 @@ struct CreateHooks { struct Diff { /// The SHA1 of a commit commit1: String, - /// The SHA1 of another commit. - /// If you leave this blank, + /// The SHA1 of another commit. + /// If you leave this blank, /// it will check the different between the commit1 and /// your current result folder - commit2: Option<String> + commit2: Option<String>, } - fn main() { let args = Cli::parse(); @@ -139,7 +144,16 @@ fn main() { init::init_and_hook(init.hooks, &init.compression, &init.mode); } Commands::Commit(commit) => { - commit::commit(commit.compression, String::from(""), commit.update); + if commit.revert { + if commit.revert == commit.update { + eprintln!("Error: You moust choose between --revert and --update option") + } + } + if !commit.revert { + commit::commit(commit.compression, String::from(""), commit.update); + } else { + commit::revert_commit(); + } } Commands::List(list) => { list::borg_list(list.first, list.last, &list.archive); @@ -156,5 +170,8 @@ fn main() { Commands::Diff(diff) => { diff::compute_diff(&diff.commit1, &diff.commit2); } + Commands::DeleteHooks => { + create_hooks::delete_hooks(); + } } }