From cefd5dc50548b846b2f383c1a0d2a5168cd2553a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 16 Sep 2020 01:46:41 +0200 Subject: 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. --- src/lib.rs | 9 ++++++--- src/main.rs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 46e0fc8..1b9689a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,11 @@ #![warn(rust_2018_idioms)] +use std::io::Write; + use git2::Repository; -pub fn write_since() { +pub fn write_since(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()); } -- cgit v1.2.3