Make changes based on @jyn514's comments

This commit is contained in:
Cassandra Fridkin 2020-10-05 22:00:43 -04:00
parent d585c96eaf
commit 0845627f73
No known key found for this signature in database
GPG key ID: B06380CCA613333A

View file

@ -46,8 +46,12 @@ pub fn setup(src_path: &Path, include_name: &str) {
_ => return,
};
println!();
t!(install_git_hook_maybe(src_path));
println!();
println!("To get started, try one of the following commands:");
for cmd in suggestions {
println!("- `x.py {}`", cmd);
@ -102,10 +106,10 @@ simply delete the `pre-commit` file from .git/hooks."
let should_install = loop {
print!("Would you like to install the git hook?: [y/N] ");
io::stdout().flush()?;
input.clear();
io::stdin().read_line(&mut input)?;
break match input.trim().to_lowercase().as_str() {
"y" | "yes" => true,
// is this the right way to check for "entered nothing"?
"n" | "no" | "" => false,
_ => {
println!("error: unrecognized option '{}'", input.trim());
@ -115,14 +119,17 @@ simply delete the `pre-commit` file from .git/hooks."
};
};
if should_install {
let src = src_path.join("/etc/pre-commit.rs");
let dst = src_path.join("/.git/hooks/pre-commit");
fs::hard_link(src, dst)?;
println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`");
Ok(if should_install {
let src = src_path.join("src").join("etc").join("pre-commit.sh");
let dst = src_path.join(".git").join("hooks").join("pre-commit");
match fs::hard_link(src, dst) {
Err(e) => println!(
"x.py encountered an error -- do you already have the git hook installed?\n{}",
e
),
Ok(_) => println!("Linked `src/etc/pre-commit.sh` to `.git/hooks/pre-commit`"),
};
} else {
println!("Ok, skipping installation!");
};
Ok(())
})
}