MCPcopy Create free account
hub / github.com/celer-pkg/celer / validateAndCleanInput

Method validateAndCleanInput

cmds/cmd_install.go:124–151  ·  view source on GitHub ↗

validateAndCleanInput validates and cleans the package name@version input.

(nameVersion string)

Source from the content-addressed store, hash-verified

122
123// validateAndCleanInput validates and cleans the package name@version input.
124func (i *installCmd) validateAndCleanInput(nameVersion string) (string, error) {
125 if strings.TrimSpace(nameVersion) == "" {
126 return "", fmt.Errorf("package name cannot be empty")
127 }
128
129 // In Windows PowerShell, when handling completion,
130 // "`" is automatically added as an escape character before the "@".
131 // We need to remove this escape character.
132 cleaned := strings.ReplaceAll(nameVersion, "`", "")
133 cleaned = strings.TrimSpace(cleaned)
134
135 parts := strings.Split(cleaned, "@")
136 if len(parts) != 2 {
137 return "", fmt.Errorf("package must be specified in name@version format (e.g., opencv@4.8.0)")
138 }
139
140 name := strings.TrimSpace(parts[0])
141 version := strings.TrimSpace(parts[1])
142
143 if name == "" {
144 return "", fmt.Errorf("package name cannot be empty")
145 }
146 if version == "" {
147 return "", fmt.Errorf("package version cannot be empty")
148 }
149
150 return name + "@" + version, nil
151}
152
153func (i *installCmd) install(nameVersion string) error {
154 platformName := expr.If(i.celer.Platform().GetName() != "", i.celer.Platform().GetName(), "native")

Callers 3

runInstallMethod · 0.95

Calls

no outgoing calls

Tested by 2