validateAndCleanInput validates and cleans the package name@version input.
(nameVersion string)
| 122 | |
| 123 | // validateAndCleanInput validates and cleans the package name@version input. |
| 124 | func (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 | |
| 153 | func (i *installCmd) install(nameVersion string) error { |
| 154 | platformName := expr.If(i.celer.Platform().GetName() != "", i.celer.Platform().GetName(), "native") |
no outgoing calls