_ => 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);
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());
};
};
- 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(())
+ })
}