ParseTemplate extracts parameter names from a command template e.g., "systemctl status {service}" -> ["service"]
(cmd string)
| 214 | // ParseTemplate extracts parameter names from a command template |
| 215 | // e.g., "systemctl status {service}" -> ["service"] |
| 216 | func ParseTemplate(cmd string) CommandTemplate { |
| 217 | var params []string |
| 218 | start := -1 |
| 219 | |
| 220 | for i, ch := range cmd { |
| 221 | if ch == '{' { |
| 222 | start = i |
| 223 | } else if ch == '}' && start != -1 { |
| 224 | param := cmd[start+1 : i] |
| 225 | params = append(params, param) |
| 226 | start = -1 |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return CommandTemplate{ |
| 231 | Template: cmd, |
| 232 | Parameters: params, |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // FillTemplate replaces placeholders with actual values |
| 237 | // e.g., "systemctl status {service}" + {"service": "nginx"} -> "systemctl status nginx" |
no outgoing calls