MCPcopy Index your code
hub / github.com/voidint/g / selfUninstall

Function selfUninstall

cli/self_uninstall.go:30–77  ·  view source on GitHub ↗
(*cli.Context)

Source from the content-addressed store, hash-verified

28)
29
30func selfUninstall(*cli.Context) error {
31 menu := wmenu.NewMenu("Are you sure you want to uninstall g?")
32 menu.IsYesNo(wmenu.DefY)
33 menu.Action(func(opts []wmenu.Opt) error {
34 if opts[0].Value.(string) != "yes" {
35 return nil
36 }
37
38 // Remove the g home directory and g binary files
39 exePath, err := os.Executable()
40 if err != nil {
41 return err
42 }
43 rmPaths := []string{exePath}
44
45 for {
46 if binPath, e := os.Readlink(exePath); e == nil && binPath != exePath {
47 rmPaths = append(rmPaths, binPath)
48 exePath = binPath
49 } else {
50 break
51 }
52 }
53
54 rmPaths = append(rmPaths, ghomeDir)
55
56 var manRmPaths []string
57 for i := range rmPaths {
58 if err = os.RemoveAll(rmPaths[i]); err != nil {
59 manRmPaths = append(manRmPaths, rmPaths[i])
60 } else {
61 fmt.Println("Remove", rmPaths[i])
62 }
63 }
64
65 if len(manRmPaths) > 0 {
66 fmt.Fprintln(os.Stderr, "Please manually remove the following files or directories:")
67 for i := range manRmPaths {
68 fmt.Fprintln(os.Stderr, manRmPaths[i])
69 }
70 }
71 return nil
72 })
73 if err := menu.Run(); err != nil {
74 return cli.Exit(errstring(err), 1)
75 }
76 return nil
77}

Callers

nothing calls this directly

Calls 1

errstringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…