Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/version-update.go
2497 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"time"
10
11
"github.com/gitpod-io/local-app/pkg/config"
12
"github.com/gitpod-io/local-app/pkg/constants"
13
"github.com/gitpod-io/local-app/pkg/selfupdate"
14
"github.com/sagikazarmark/slog-shim"
15
"github.com/spf13/cobra"
16
)
17
18
var versionUpdateCmd = &cobra.Command{
19
Use: "update",
20
Short: "Updates the CLI to the latest version",
21
RunE: func(cmd *cobra.Command, args []string) error {
22
cmd.SilenceUsage = true
23
24
dlctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second)
25
defer cancel()
26
27
cfg := config.FromContext(cmd.Context())
28
gpctx, err := cfg.GetActiveContext()
29
if err != nil {
30
return err
31
}
32
33
mf, err := selfupdate.DownloadManifest(dlctx, gpctx.Host.URL.String())
34
if err != nil {
35
return err
36
}
37
if !selfupdate.NeedsUpdate(constants.Version, mf) {
38
slog.Info("already up to date")
39
return nil
40
}
41
42
slog.Info("updating to latest version " + mf.Version.String())
43
err = selfupdate.ReplaceSelf(dlctx, mf)
44
if err != nil {
45
return err
46
}
47
48
return nil
49
},
50
}
51
52
func init() {
53
versionCmd.AddCommand(versionUpdateCmd)
54
}
55
56