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