| 150 | } |
| 151 | |
| 152 | pub fn parse(&self, input: &str) -> Option<(&Command, Vec<String>)> { |
| 153 | let input = input.trim_start(); |
| 154 | |
| 155 | if !input.starts_with('/') { |
| 156 | return None; |
| 157 | } |
| 158 | |
| 159 | let input = &input[1..]; |
| 160 | let parts: Vec<&str> = input.split_whitespace().collect(); |
| 161 | |
| 162 | if parts.is_empty() { |
| 163 | return None; |
| 164 | } |
| 165 | |
| 166 | let name = parts[0]; |
| 167 | let args: Vec<String> = parts[1..].iter().map(|s| s.to_string()).collect(); |
| 168 | |
| 169 | self.commands.get(name).map(|cmd| (cmd, args)) |
| 170 | } |
| 171 | |
| 172 | /// Execute a command and return the rendered template |
| 173 | pub fn execute(&self, name: &str, ctx: CommandContext) -> anyhow::Result<String> { |