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,24 +1,31 @@
use crate::usage::Usage;
use failure::Fallible;
use std::io;
use termcolor::WriteColor;
pub(crate) fn execute(command_name: String, summary: bool) -> Fallible<()> {
pub(crate) fn execute<W: WriteColor>(
w: &mut W,
command_name: String,
summary: bool,
) -> Fallible<()> {
let usage = Usage::new();
usage.write_help(io::stdout(), command_name, summary)?;
usage.write_help(w, command_name, summary)?;
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
use crate::invocation::cmd::test::*;
#[test]
fn test_summary() {
execute("task".to_owned(), true).unwrap();
let mut w = test_writer();
execute(&mut w, "task".to_owned(), true).unwrap();
}
#[test]
fn test_long() {
execute("task".to_owned(), false).unwrap();
let mut w = test_writer();
execute(&mut w, "task".to_owned(), false).unwrap();
}
}