diff options
author | Teddy Wing | 2020-09-16 01:46:41 +0200 |
---|---|---|
committer | Teddy Wing | 2020-09-16 01:46:41 +0200 |
commit | cefd5dc50548b846b2f383c1a0d2a5168cd2553a (patch) | |
tree | effe9d78f7a1c078d7fd8b2c92b6010cbd59fc82 | |
parent | b0aa9334017e433225175d323732472c35f51aed (diff) | |
download | git-todo-cefd5dc50548b846b2f383c1a0d2a5168cd2553a.tar.bz2 |
write_since(): Take an arbitrary `Write`r
Instead of always printing to standard output, have the function take a
writer to write the output to.
-rw-r--r-- | src/lib.rs | 9 | ||||
-rw-r--r-- | src/main.rs | 2 |
2 files changed, 7 insertions, 4 deletions
@@ -1,9 +1,11 @@ #![warn(rust_2018_idioms)] +use std::io::Write; + use git2::Repository; -pub fn write_since() { +pub fn write_since<W: Write>(write_to: &mut W) { let repo = Repository::open(".").unwrap(); // let head = repo.head().unwrap().target().unwrap(); @@ -32,12 +34,13 @@ pub fn write_since() { let l = std::str::from_utf8(line.content()).unwrap(); if l.contains("TODO") { - print!( + write!( + write_to, "{}:{}:{}", delta.new_file().path().unwrap().display(), line_number, l, - ); + ).unwrap(); } } diff --git a/src/main.rs b/src/main.rs index 2648353..60f12d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,5 +4,5 @@ use git_todo::write_since; fn main() { - write_since(); + write_since(&mut std::io::stdout()); } |