mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* Add version command * Restructure config package * Bring back config get and config set * Support login host without protocol scheme * Add autoupdate functionality * Generate update manifest during build * Better update failure behavior * Add latest to version command * Add version update command * Use cannonical semver form
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License.AGPL.txt in the project root for license information.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/gitpod-io/local-app/pkg/constants"
|
|
"github.com/gitpod-io/local-app/pkg/prettyprint"
|
|
"github.com/gitpod-io/local-app/pkg/selfupdate"
|
|
"github.com/sagikazarmark/slog-shim"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var versionCmd = &cobra.Command{
|
|
Use: "version",
|
|
Short: "Prints the CLI version",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
type Version struct {
|
|
Version string `print:"version"`
|
|
GitCommit string `print:"commit"`
|
|
BuildTime string `print:"built at"`
|
|
Latest string `print:"latest"`
|
|
}
|
|
v := Version{
|
|
Version: constants.Version.String(),
|
|
GitCommit: constants.GitCommit,
|
|
BuildTime: constants.MustParseBuildTime().Format(time.RFC3339),
|
|
Latest: "<not available>",
|
|
}
|
|
|
|
if !versionOpts.DontCheckLatest {
|
|
dlctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
mf, err := selfupdate.DownloadManifestFromActiveContext(dlctx)
|
|
if err != nil {
|
|
slog.Debug("cannot download manifest", "err", err)
|
|
}
|
|
if mf != nil {
|
|
v.Latest = mf.Version.String()
|
|
}
|
|
}
|
|
|
|
return WriteTabular([]Version{v}, versionOpts.Format, prettyprint.WriterFormatNarrow)
|
|
},
|
|
}
|
|
|
|
var versionOpts struct {
|
|
Format formatOpts
|
|
DontCheckLatest bool
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(versionCmd)
|
|
addFormatFlags(versionCmd, &versionOpts.Format)
|
|
|
|
versionCmd.Flags().BoolVar(&versionOpts.DontCheckLatest, "dont-check-latest", false, "Don't check for the latest available version")
|
|
}
|
|
|
|
// isVersionCommand returns true if the given command is a version command
|
|
func isVersionCommand(cmd *cobra.Command) bool {
|
|
return cmd == versionCmd || cmd.Parent() == versionCmd
|
|
}
|