modcli/commands/
hello.rs

1use crate::command::Command;
2
3pub struct HelloCommand;
4
5impl Command for HelloCommand {
6    fn name(&self) -> &'static str {
7        "hello"
8    }
9
10    fn help(&self) -> Option<&str> {
11        Some("Greets the user")
12    }
13
14    fn validate(&self, args: &[String]) -> Result<(), String> {
15        if args.len() > 1 {
16            Err("Hello takes at most one argument (your name).".into())
17        } else {
18            Ok(())
19        }
20    }
21
22    fn execute(&self, args: &[String]) {
23        if let Some(name) = args.get(0) {
24            println!("Hello, {}!", name);
25        } else {
26            println!("Hello!");
27        }
28    }
29}