MCPcopy Create free account
hub / github.com/Melkeydev/govm / DeleteVersion

Function DeleteVersion

internal/cli/cli.go:232–275  ·  view source on GitHub ↗
(version string)

Source from the content-addressed store, hash-verified

230}
231
232func DeleteVersion(version string) {
233 fmt.Printf("🔍 Looking for installed Go version matching %s...\n", version)
234 matchedVersion, err := findInstalledVersion(version)
235 if err != nil {
236 fmt.Printf("❌ %s\n", err)
237 return
238 }
239
240 homeDir, err := os.UserHomeDir()
241 if err != nil {
242 fmt.Printf("❌ Failed to get home directory: %v\n", err)
243 return
244 }
245
246 activeVersionFile := filepath.Join(homeDir, ".govm", "active_version")
247 activeVersion := ""
248 if versionBytes, err := os.ReadFile(activeVersionFile); err == nil {
249 activeVersion = string(versionBytes)
250 }
251
252 if matchedVersion.Version == activeVersion {
253 fmt.Printf("❌ Cannot delete active version. Switch to another version first using 'govm use'.\n")
254 return
255 }
256
257 fmt.Printf("⚠️ Are you sure you want to delete Go %s? (y/N): ", matchedVersion.Version)
258 var response string
259 fmt.Scanln(&response)
260
261 if strings.ToLower(response) != "y" {
262 fmt.Println("🛑 Operation canceled.")
263 return
264 }
265
266 fmt.Printf("🗑️ Deleting Go %s...\n", matchedVersion.Version)
267
268 msg := utils.DeleteVersion(matchedVersion)()
269 switch msg := msg.(type) {
270 case utils.ErrMsg:
271 fmt.Printf("❌ Failed to delete version: %v\n", msg)
272 case utils.DeleteCompleteMsg:
273 fmt.Printf("✅ Successfully deleted Go %s\n", matchedVersion.Version)
274 }
275}
276

Callers 1

handleCommandLineFunction · 0.92

Calls 2

DeleteVersionFunction · 0.92
findInstalledVersionFunction · 0.85

Tested by

no test coverage detected