modcli/commands/
benchmark.rs

1use crate::command::Command;
2use std::time::Instant;
3
4pub struct BenchmarkCommand;
5
6impl BenchmarkCommand {
7    pub fn new() -> Self {
8        Self
9    }
10}
11
12impl Command for BenchmarkCommand {
13    fn name(&self) -> &str {
14        "benchmark"
15    }
16
17    fn aliases(&self) -> &[&str] {
18        &["bench"]
19    }
20
21    fn help(&self) -> Option<&str> {
22        Some("Benchmark the execution time of a command")
23    }
24
25    fn validate(&self, args: &[String]) -> Result<(), String> {
26        if args.is_empty() {
27            Err("Usage: benchmark <command> [args]".into())
28        } else {
29            Ok(())
30        }
31    }
32
33    fn execute(&self, args: &[String]) {
34        let cmd_name = &args[0];
35        let cmd_args = &args[1..];
36
37        use crate::loader::CommandRegistry;
38        let mut registry = CommandRegistry::new();
39        registry.load_internal_commands(); // Load commands again just for access
40
41        if let Some(command) = registry.get(cmd_name) {
42            let start = Instant::now();
43            command.execute(cmd_args);
44            let elapsed = start.elapsed();
45            println!("⏱  Completed in {:?}", elapsed);
46        } else {
47            eprintln!("Unknown command: {}", cmd_name);
48        }
49    }
50}