aboutsummaryrefslogtreecommitdiff
path: root/hooked
diff options
context:
space:
mode:
authorMichael Gattozzi <mgattozzi@gmail.com>2019-11-26 15:04:17 -0500
committerMichael Gattozzi <mgattozzi@gmail.com>2019-11-26 15:40:31 -0500
commit51e92e14357ff7abca4ba04f7a3580b6a66ff442 (patch)
tree0d836521f605debcfa9915c57b4236e8ed0d89a8 /hooked
parentb8635f6a4f2429382fafdbdd1e0b8bb1f8b7b296 (diff)
Add logging output to hooked
We really should be logging what's going on as each of these tools run. Before this change hooked just ran without any indication of what was going on. This change adds logging with info level for the end user by default, with debug and trace statements while developing the code being an option as well.
Diffstat (limited to 'hooked')
-rw-r--r--hooked/Cargo.toml4
-rw-r--r--hooked/src/main.rs26
2 files changed, 28 insertions, 2 deletions
diff --git a/hooked/Cargo.toml b/hooked/Cargo.toml
index 2a7d477..8f5a03a 100644
--- a/hooked/Cargo.toml
+++ b/hooked/Cargo.toml
@@ -3,7 +3,7 @@ name = "hooked"
version = "0.1.0"
authors = ["Michael Gattozzi <mgattozzi@gmail.com>"]
edition = "2018"
-
+default-run = "hooked"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
@@ -12,6 +12,8 @@ paw = "1.0"
shared = { path = "../shared" }
structopt = { version = "0.3", features = ["paw"] }
unicode-segmentation = "1.3"
+log = "0.4"
+pretty_env_logger = "0.3"
[dev-dependencies]
tempfile = "3"
diff --git a/hooked/src/main.rs b/hooked/src/main.rs
index d412469..a3d8199 100644
--- a/hooked/src/main.rs
+++ b/hooked/src/main.rs
@@ -1,6 +1,7 @@
#[cfg(windows)]
use anyhow::bail;
use anyhow::Result;
+use log::*;
use shared::find_root;
#[cfg(not(windows))]
use std::os::unix::fs::{
@@ -10,6 +11,7 @@ use std::os::unix::fs::{
#[cfg(windows)]
use std::os::windows::fs::symlink_file;
use std::{
+ env,
fs,
io::Write,
};
@@ -43,10 +45,14 @@ enum Args {
#[paw::main]
fn main(args: Args) {
+ env::var("RUST_LOG").map(drop).unwrap_or_else(|_| {
+ env::set_var("RUST_LOG", "info");
+ });
+ pretty_env_logger::init();
if let Err(e) = match args {
Args::Init => init(),
} {
- eprintln!("{}", e);
+ error!("{}", e);
std::process::exit(1);
}
}
@@ -57,29 +63,47 @@ fn init() -> Result<()> {
let root = find_root()?;
let git_hooks = &root.join(".git").join("hooks");
+ debug!("git_hooks base path: {}", git_hooks.display());
let root = root.join(".dev-suite").join("hooked");
+ debug!("root base path: {}", root.display());
fs::create_dir_all(&root)?;
for hook in &HOOKS {
let path = &root.join(hook);
+ debug!("dev-suite hook path: {}", path.display());
let git_hook = &git_hooks.join(hook);
+ debug!("git_hook path: {}", git_hook.display());
if !path.exists() {
+ debug!("Creating dev-suite hook.");
let mut file = fs::File::create(&path)?;
+ trace!("File created.");
let mut perms = file.metadata()?.permissions();
+ debug!("Setting dev-suite hook to be executable.");
perms.set_mode(0o755);
file.set_permissions(perms)?;
+ trace!("Permissions were set.");
file.write_all(b"#! /bin/bash")?;
+ debug!("Writing data to file.");
+ debug!("Created git hook {}.", hook);
+ } else {
+ debug!("git hook {} already exists. Skipping creation.", hook);
}
let path = path.canonicalize()?;
if !git_hook.exists() {
+ debug!("Symlinking git hook {}.", hook);
#[cfg(not(windows))]
symlink(&path, &git_hook)?;
#[cfg(windows)]
symlink_file(&path, &git_hook)?;
+ trace!("Symlinked git hook {} to .dev-suite/hooked/{}.", hook, hook);
}
}
+ info!(
+ "Created and symlinked tickets to .git/hooks from {}.",
+ root.display()
+ );
Ok(())
}