Skip to content

Commit bf7834b

Browse files
Added build date to version output.
1 parent 635cb2f commit bf7834b

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

cmd/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ const (
4747
envPrefix = "BOOTLOG"
4848
)
4949

50-
// Version is set during the build process using the -ldflags option.
50+
// Ver (version) is set during the build process using the -ldflags option.
5151
// If not set, it defaults to "unknown".
5252
var Ver string = "unknown"
5353

54+
// Date of build for use with the version command
55+
var BuildDate string = "unknown"
56+
5457
// rootCmd represents the base command when called without any subcommands
5558
var rootCmd = &cobra.Command{
5659
Use: "bootlogger",

cmd/version.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ var versionCmd = &cobra.Command{
3434
Short: "Print the bootlogger version number to the console.",
3535
Example: " bootlogger version\n bootlogger ver",
3636
Run: func(cmd *cobra.Command, args []string) {
37-
color.New(color.FgHiWhite).Printf("bootlogger version:")
37+
color.New(color.FgHiWhite).Printf("version:")
3838
if Ver == "unknown" {
3939
color.New(color.FgHiRed).Printf(" Version was not set during build.\n")
40-
} else {
41-
color.New(color.FgHiGreen).Printf(" %s\n", Ver)
40+
return
41+
}
42+
color.New(color.FgHiGreen).Printf(" %s\n", Ver)
43+
if BuildDate != "unknown" {
44+
color.New(color.FgHiWhite).Printf("build date:")
45+
color.New(color.FgHiGreen).Printf(" %s\n", BuildDate)
4246
}
43-
4447
},
4548
}
4649

0 commit comments

Comments
 (0)