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,26 +1,32 @@
use failure::Fallible;
use taskchampion::{server::Server, Replica};
use termcolor::WriteColor;
pub(crate) fn execute(replica: &mut Replica, server: &mut Box<dyn Server>) -> Fallible<()> {
pub(crate) fn execute<W: WriteColor>(
w: &mut W,
replica: &mut Replica,
server: &mut Box<dyn Server>,
) -> Fallible<()> {
replica.sync(server)?;
println!("sync complete.");
write!(w, "sync complete.\n")?;
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
use crate::invocation::cmd::test::{test_replica, test_server};
use crate::invocation::cmd::test::*;
use tempdir::TempDir;
#[test]
fn test_add() {
let mut w = test_writer();
let mut replica = test_replica();
let server_dir = TempDir::new("test").unwrap();
let mut server = test_server(&server_dir);
// this just has to not fail -- the details of the actual sync are
// tested thoroughly in the taskchampion crate
execute(&mut replica, &mut server).unwrap();
// Note that the details of the actual sync are tested thoroughly in the taskchampion crate
execute(&mut w, &mut replica, &mut server).unwrap();
assert_eq!(&w.into_string(), "sync complete.\n")
}
}