use a generic Write instance for command output
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
use failure::Fallible;
|
||||
use termcolor::{ColorSpec, WriteColor};
|
||||
|
||||
pub(crate) fn execute() -> Fallible<()> {
|
||||
println!("TaskChampion {}", env!("CARGO_PKG_VERSION"));
|
||||
pub(crate) fn execute<W: WriteColor>(w: &mut W) -> Fallible<()> {
|
||||
write!(w, "TaskChampion ")?;
|
||||
w.set_color(ColorSpec::new().set_bold(true))?;
|
||||
write!(w, "{}\n", env!("CARGO_PKG_VERSION"))?;
|
||||
w.reset()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::invocation::cmd::test::*;
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
execute().unwrap();
|
||||
let mut w = test_writer();
|
||||
execute(&mut w).unwrap();
|
||||
assert!(w.into_string().starts_with("TaskChampion "));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user