use a generic Write instance for command output

This commit is contained in:
Dustin J. Mitchell
2020-12-20 19:45:24 -05:00
parent 6b550e7516
commit 7d17740ca8
13 changed files with 154 additions and 46 deletions

View File

@@ -1,21 +1,23 @@
use failure::Fallible;
use taskchampion::Replica;
use termcolor::WriteColor;
pub(crate) fn execute(replica: &mut Replica) -> Fallible<()> {
pub(crate) fn execute<W: WriteColor>(w: &mut W, replica: &mut Replica) -> Fallible<()> {
replica.gc()?;
println!("garbage collected.");
write!(w, "garbage collected.\n")?;
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
use crate::invocation::cmd::test::test_replica;
use crate::invocation::cmd::test::*;
#[test]
fn test_gc() {
let mut w = test_writer();
let mut replica = test_replica();
execute(&mut replica).unwrap();
// this mostly just needs to not fail!
execute(&mut w, &mut replica).unwrap();
assert_eq!(&w.into_string(), "garbage collected.\n")
}
}