use a generic Write instance for command output
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user