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

Function install

cli/install.go:40–177  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

38)
39
40func install(ctx *cli.Context) (err error) {
41 vname := ctx.Args().First()
42 if vname == "" {
43 return cli.ShowSubcommandHelp(ctx)
44 }
45
46 // Find matching Go version.
47 c, err := collector.NewCollector(strings.Split(os.Getenv(mirrorEnv), mirrorSep)...)
48 if err != nil {
49 return cli.Exit(errstring(err), 1)
50 }
51 items, err := c.AllVersions()
52 if err != nil {
53 return cli.Exit(errstring(err), 1)
54 }
55
56 v, err := version.NewFinder(items,
57 version.WithFinderPackageKind(version.ArchiveKind),
58 version.WithFinderGoos(runtime.GOOS),
59 version.WithFinderGoarch(runtime.GOARCH),
60 ).Find(vname)
61 if err != nil {
62 return cli.Exit(errstring(err), 1)
63 }
64
65 vname = v.Name()
66 targetV := filepath.Join(versionsDir, vname)
67
68 // Check if the version is already installed.
69 var finfo os.FileInfo
70 if finfo, err = os.Stat(targetV); err == nil && finfo.IsDir() {
71 return cli.Exit(fmt.Sprintf("[g] %q version has been installed.", vname), 1)
72 }
73
74 // Find installation packages for current platform
75 pkgs, err := v.FindPackages(version.ArchiveKind, runtime.GOOS, runtime.GOARCH)
76 if err != nil {
77 return cli.Exit(errstring(err), 1)
78 }
79 var pkg version.Package
80 if len(pkgs) > 1 {
81 menu := wmenu.NewMenu("Please select the package you want to install.")
82 menu.AddColor(
83 wlog.Color{Code: ct.Green},
84 wlog.Color{Code: ct.Yellow},
85 wlog.Color{Code: ct.Magenta},
86 wlog.Color{Code: ct.Yellow},
87 )
88 menu.Action(func(opts []wmenu.Opt) error {
89 pkg = opts[0].Value.(version.Package)
90 return nil
91 })
92 for i := range pkgs {
93 if i == 0 {
94 menu.Option(pkgs[i].FileName, pkgs[i], true, nil)
95 } else {
96 menu.Option(" "+pkgs[i].FileName, pkgs[i], false, nil)
97 }

Callers

nothing calls this directly

Calls 13

AllVersionsMethod · 0.95
DownloadWithProgressMethod · 0.95
VerifyChecksumMethod · 0.95
NewCollectorFunction · 0.92
NewFinderFunction · 0.92
WithFinderPackageKindFunction · 0.92
WithFinderGoosFunction · 0.92
WithFinderGoarchFunction · 0.92
errstringFunction · 0.85
switchVersionFunction · 0.85
FindMethod · 0.80
FindPackagesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…