use super::available_commands; use crate::configuration::Configuration; use std::io::Result; pub struct Help; impl Help { pub fn new() -> Self { Help } } impl super::Command for Help { fn before_dependencies(&self) -> Vec> { vec![] } fn execute(&self, _: Option<&String>, _: &Configuration, _: &str) -> Result<()> { let commands = available_commands(); println!("Usage:"); println!(); for command in commands { print!("blog {} ", command.command()); println!("{}", command.help()); } Ok(()) } fn after_dependencies(&self) -> Vec> { vec![] } fn command(&self) -> &'static str { "help" } fn help(&self) -> &'static str { "\t\t\t\tPrints this help" } } #[cfg(test)] mod tests { use super::*; use crate::command::Command; use crate::configuration::Configuration; #[test] fn test_help_command() { let help = Help::new(); let configuration = Configuration::new(); help.execute(None, &configuration, "") .expect("Could not call help"); } #[test] fn help_before_dependencies() { let help = Help::new(); let dependencies = help.before_dependencies(); assert_eq!(dependencies.len(), 0); } #[test] fn help_after_dependencies() { let help = Help::new(); let dependencies = help.after_dependencies(); assert_eq!(dependencies.len(), 0); } // These two tests feel pointless but I'm doing it for the coverage :p #[test] fn help_command_output() { let help = Help::new(); help.command(); } #[test] fn help_help_output() { let help = Help::new(); help.help(); } }