Add the uninstall subcommand.
This commit is contained in:
parent
0d009834fe
commit
54657adaf0
|
@ -24,7 +24,14 @@ pub enum MainSubcommands {
|
||||||
/// Install Hooked into ".git/hooks".
|
/// Install Hooked into ".git/hooks".
|
||||||
Install {
|
Install {
|
||||||
/// Overwrite existing files.
|
/// Overwrite existing files.
|
||||||
#[clap(long, default_value = "false")]
|
#[clap(long)]
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Remove installed hooks.
|
||||||
|
Uninstall {
|
||||||
|
/// Remove hooks not installed by Hooked.
|
||||||
|
#[clap(long)]
|
||||||
|
all: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fs::{set_permissions, write, Permissions},
|
fs::{read_to_string, remove_file, set_permissions, write, Permissions},
|
||||||
os::unix::fs::PermissionsExt,
|
os::unix::fs::PermissionsExt,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
@ -61,6 +61,25 @@ fn main() -> Result<()> {
|
||||||
set_permissions(hook_path, Permissions::from_mode(0o775))?;
|
set_permissions(hook_path, Permissions::from_mode(0o775))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MainSubcommands::Uninstall { all } => {
|
||||||
|
for hook_type in HOOK_TYPES {
|
||||||
|
let hook_path = git_hooks_dir.join(hook_type);
|
||||||
|
if !hook_path.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let hook_contents = read_to_string(&hook_path)?;
|
||||||
|
if all || hook_contents.contains("# Installed by Hooked.") {
|
||||||
|
remove_file(hook_path)?;
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"{:?} wasn't installed by Hooked, use --all to remove it",
|
||||||
|
hook_path
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue