mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Add buildinfo package to embed version (#840)
This also resolves build time and commit hash using the Go 1.18 debug/buildinfo package. An external URL is outputted on running version as well to easily route the caller to a release or commit.
This commit is contained in:
+15
@@ -4,12 +4,14 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/kirsle/configdir"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/coder/coder/cli/buildinfo"
|
||||
"github.com/coder/coder/cli/cliui"
|
||||
"github.com/coder/coder/cli/config"
|
||||
"github.com/coder/coder/codersdk"
|
||||
@@ -28,6 +30,7 @@ const (
|
||||
func Root() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "coder",
|
||||
Version: buildinfo.Version(),
|
||||
SilenceUsage: true,
|
||||
Long: ` ▄█▀ ▀█▄
|
||||
▄▄ ▀▀▀ █▌ ██▀▀█▄ ▐█
|
||||
@@ -55,6 +58,7 @@ func Root() *cobra.Command {
|
||||
`Flags:`, header.Render("Flags:"),
|
||||
`Additional help topics:`, header.Render("Additional help:"),
|
||||
).Replace(cmd.UsageTemplate()))
|
||||
cmd.SetVersionTemplate(versionTemplate())
|
||||
|
||||
cmd.AddCommand(
|
||||
configSSH(),
|
||||
@@ -142,3 +146,14 @@ func isTTY(cmd *cobra.Command) bool {
|
||||
}
|
||||
return isatty.IsTerminal(file.Fd())
|
||||
}
|
||||
|
||||
func versionTemplate() string {
|
||||
template := `Coder {{printf "%s" .Version}}`
|
||||
buildTime, valid := buildinfo.Time()
|
||||
if valid {
|
||||
template += " " + buildTime.Format(time.UnixDate)
|
||||
}
|
||||
template += "\r\n" + buildinfo.ExternalURL()
|
||||
template += "\r\n"
|
||||
return template
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user