]> git.r.bdr.sh - rbdr/blog/blame - src/command/help.rs
Add help
[rbdr/blog] / src / command / help.rs
CommitLineData
2f579cf4 1use std::env::args;
d620665f 2use std::io::Result;
2f579cf4 3use super::available_commands;
d620665f
RBR
4
5pub struct Help;
6
7impl Help {
8 pub fn new() -> Self {
9 Help
10 }
11}
12
13impl super::Command for Help {
14 fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
15 vec![]
16 }
17
2f579cf4
RBR
18 fn execute(&self, _: Option<&String>) -> Result<()> {
19 let arguments: Vec<String> = args().collect();
20 let app_name = arguments.get(0).map_or("blog", |s| s.as_str());
21 let commands = available_commands();
22 println!("Usage:");
23 println!("");
24 for command in commands {
25 print!("{} {} ", app_name, command.command());
26 println!("{}", command.help());
27 }
d620665f
RBR
28 return Ok(())
29 }
30
31 fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
32 vec![]
33 }
34
35 fn command(&self) -> &'static str {
36 "help"
37 }
38
39 fn help(&self) -> &'static str {
40 "\t\t\t\tPrints this help"
41 }
42}