From 2f579cf4c0d8ff95af78103783c7ca8f951cc797 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Fri, 23 Feb 2024 21:03:40 +0000 Subject: Add help --- src/command/help.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/command/help.rs') diff --git a/src/command/help.rs b/src/command/help.rs index 9b98393..628fd5a 100644 --- a/src/command/help.rs +++ b/src/command/help.rs @@ -1,4 +1,6 @@ +use std::env::args; use std::io::Result; +use super::available_commands; pub struct Help; @@ -13,8 +15,16 @@ impl super::Command for Help { vec![] } - fn execute(&self, input: Option<&String>) -> Result<()> { - println!("Help: {:?}!", input); + fn execute(&self, _: Option<&String>) -> Result<()> { + let arguments: Vec = args().collect(); + let app_name = arguments.get(0).map_or("blog", |s| s.as_str()); + let commands = available_commands(); + println!("Usage:"); + println!(""); + for command in commands { + print!("{} {} ", app_name, command.command()); + println!("{}", command.help()); + } return Ok(()) } -- cgit