MCPcopy Create free account
hub / github.com/nhost/nhost / commandUpgrade

Function commandUpgrade

cli/cmd/software/upgrade.go:27–83  ·  view source on GitHub ↗
(ctx context.Context, cmd *cli.Command)

Source from the content-addressed store, hash-verified

25}
26
27func commandUpgrade(ctx context.Context, cmd *cli.Command) error {
28 ce := clienv.FromCLI(cmd)
29
30 mgr := software.NewManager()
31
32 releases, err := mgr.GetReleases(ctx, cmd.Root().Version)
33 if err != nil {
34 return fmt.Errorf("failed to get releases: %w", err)
35 }
36
37 if len(releases) == 0 {
38 ce.Infoln("You have the latest version. Hurray!")
39 return nil
40 }
41
42 latest := releases[0]
43 if latest.TagName == cmd.Root().Version {
44 ce.Infoln("You have the latest version. Hurray!")
45 return nil
46 }
47
48 ce.Infoln("Upgrading to %s...", latest.TagName)
49
50 version := latest.TagName
51 s := strings.Split(latest.TagName, "@")
52
53 if len(s) == 2 { //nolint:mnd
54 version = s[1]
55 }
56
57 want := fmt.Sprintf("cli-%s-%s-%s.tar.gz", version, runtime.GOOS, runtime.GOARCH)
58
59 var url string
60
61 for _, asset := range latest.Assets {
62 if asset.Name == want {
63 url = asset.BrowserDownloadURL
64 }
65 }
66
67 if url == "" {
68 return fmt.Errorf("failed to find asset for %s", want) //nolint:err113
69 }
70
71 tmpFile, err := os.CreateTemp(os.TempDir(), "nhost-cli-")
72 if err != nil {
73 return fmt.Errorf("failed to create temporary file: %w", err)
74 }
75 defer os.Remove(tmpFile.Name())
76 defer tmpFile.Close()
77
78 if err := mgr.DownloadAsset(ctx, url, tmpFile); err != nil {
79 return fmt.Errorf("failed to download asset: %w", err)
80 }
81
82 return install(cmd, ce, tmpFile.Name())
83}
84

Callers

nothing calls this directly

Calls 10

GetReleasesMethod · 0.95
DownloadAssetMethod · 0.95
FromCLIFunction · 0.92
NewManagerFunction · 0.92
installFunction · 0.85
RootMethod · 0.80
ErrorfMethod · 0.80
InfolnMethod · 0.80
NameMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected