Path: blob/main/components/local-app/cmd/version-update.go
2497 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"context"8"time"910"github.com/gitpod-io/local-app/pkg/config"11"github.com/gitpod-io/local-app/pkg/constants"12"github.com/gitpod-io/local-app/pkg/selfupdate"13"github.com/sagikazarmark/slog-shim"14"github.com/spf13/cobra"15)1617var versionUpdateCmd = &cobra.Command{18Use: "update",19Short: "Updates the CLI to the latest version",20RunE: func(cmd *cobra.Command, args []string) error {21cmd.SilenceUsage = true2223dlctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second)24defer cancel()2526cfg := config.FromContext(cmd.Context())27gpctx, err := cfg.GetActiveContext()28if err != nil {29return err30}3132mf, err := selfupdate.DownloadManifest(dlctx, gpctx.Host.URL.String())33if err != nil {34return err35}36if !selfupdate.NeedsUpdate(constants.Version, mf) {37slog.Info("already up to date")38return nil39}4041slog.Info("updating to latest version " + mf.Version.String())42err = selfupdate.ReplaceSelf(dlctx, mf)43if err != nil {44return err45}4647return nil48},49}5051func init() {52versionCmd.AddCommand(versionUpdateCmd)53}545556