]> git.r.bdr.sh - rbdr/blog/blob - src/command/help.rs
628fd5aa81a25a5371de0cfc74ab81e22f6f2c3e
[rbdr/blog] / src / command / help.rs
1 use std::env::args;
2 use std::io::Result;
3 use super::available_commands;
4
5 pub struct Help;
6
7 impl Help {
8 pub fn new() -> Self {
9 Help
10 }
11 }
12
13 impl super::Command for Help {
14 fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
15 vec![]
16 }
17
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 }
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 }