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

Method splitTemplate

internal/plugins/command-runner/validator.go:101–125  ·  view source on GitHub ↗

splitTemplate splits a template string into static parts e.g., "systemctl status {service}" -> ["systemctl status ", ""]

(template string)

Source from the content-addressed store, hash-verified

99// splitTemplate splits a template string into static parts
100// e.g., "systemctl status {service}" -> ["systemctl status ", ""]
101func (v *Validator) splitTemplate(template string) []string {
102 var parts []string
103 var current strings.Builder
104 inParam := false
105
106 for _, ch := range template {
107 if ch == '{' {
108 if current.Len() > 0 {
109 parts = append(parts, current.String())
110 current.Reset()
111 }
112 inParam = true
113 } else if ch == '}' {
114 inParam = false
115 } else if !inParam {
116 current.WriteRune(ch)
117 }
118 }
119
120 if current.Len() > 0 {
121 parts = append(parts, current.String())
122 }
123
124 return parts
125}
126
127// GetAllowedCommands returns the list of allowed commands for a target type
128func (v *Validator) GetAllowedCommands(targetType TargetType) []string {

Callers 1

Calls 2

ResetMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected