MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / ParseTemplate

Function ParseTemplate

internal/plugins/command-runner/config.go:216–234  ·  view source on GitHub ↗

ParseTemplate extracts parameter names from a command template e.g., "systemctl status {service}" -> ["service"]

(cmd string)

Source from the content-addressed store, hash-verified

214// ParseTemplate extracts parameter names from a command template
215// e.g., "systemctl status {service}" -> ["service"]
216func 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"

Callers 7

TestParseTemplateFunction · 0.85
matchesPatternMethod · 0.85

Calls

no outgoing calls

Tested by 2

TestParseTemplateFunction · 0.68