Skip to content

Commit 443adf6

Browse files
Merge pull request #4 from depot/version-command
Add build date to version
2 parents be32846 + 4916300 commit 443adf6

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

cmd/depot/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ func main() {
1414

1515
func runMain() int {
1616
buildVersion := build.Version
17+
buildDate := build.Date
1718

18-
rootCmd := root.NewCmdRoot(buildVersion)
19+
rootCmd := root.NewCmdRoot(buildVersion, buildDate)
1920

2021
if err := rootCmd.Execute(); err != nil {
2122
return 1

internal/build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package build
33
import "runtime/debug"
44

55
var Version = "dev"
6-
var BuildDate = ""
6+
var Date = ""
77

88
func init() {
99
if Version == "dev" {

pkg/cmd/root/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/depot/cli/pkg/config"
1010
)
1111

12-
func NewCmdRoot(version string) *cobra.Command {
12+
func NewCmdRoot(version, buildDate string) *cobra.Command {
1313
var cmd = &cobra.Command{
1414
Use: "depot <command> [flags]",
1515
Short: "Depot CLI",
@@ -23,15 +23,15 @@ func NewCmdRoot(version string) *cobra.Command {
2323
// Initialize config
2424
_ = config.NewConfig()
2525

26-
formattedVersion := versionCmd.Format(version)
26+
formattedVersion := versionCmd.Format(version, buildDate)
2727
cmd.SetVersionTemplate(formattedVersion)
2828
cmd.Version = formattedVersion
2929
cmd.Flags().Bool("version", false, "Print the version and exit")
3030

3131
// Child commands
3232
cmd.AddCommand(buildCmd.NewCmdBuild())
3333
cmd.AddCommand(loginCmd.NewCmdLogin())
34-
cmd.AddCommand(versionCmd.NewCmdVersion(version))
34+
cmd.AddCommand(versionCmd.NewCmdVersion(version, buildDate))
3535

3636
return cmd
3737
}

pkg/cmd/version/version.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ import (
88
"github.com/spf13/cobra"
99
)
1010

11-
func NewCmdVersion(version string) *cobra.Command {
11+
func NewCmdVersion(version, buildDate string) *cobra.Command {
1212
cmd := &cobra.Command{
1313
Use: "version",
1414
Hidden: true,
1515
Run: func(cmd *cobra.Command, args []string) {
16-
fmt.Print(Format(version))
16+
fmt.Print(Format(version, buildDate))
1717
},
1818
}
1919
return cmd
2020
}
2121

22-
func Format(version string) string {
22+
func Format(version, buildDate string) string {
2323
version = strings.TrimPrefix(version, "v")
24-
return fmt.Sprintf("depot version %s\n%s\n", version, changelogURL(version))
24+
if buildDate != "" {
25+
buildDate = fmt.Sprintf(" (%s)", buildDate)
26+
}
27+
return fmt.Sprintf("depot version %s%s\n%s\n", version, buildDate, changelogURL(version))
2528
}
2629

2730
func changelogURL(version string) string {

0 commit comments

Comments
 (0)