This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
var ( | ||
buildTime string | ||
lastCommit string | ||
semanticVersion string | ||
|
||
systemVersion = fmt.Sprintf("%s/%s", runtime.GOARCH, runtime.GOOS) | ||
golangVersion = runtime.Version() | ||
) | ||
|
||
// BuildInfo represents all necessary information about the current build. | ||
type BuildInfo struct { | ||
BuildTime string | ||
LastCommit string | ||
SemanticVersion string | ||
SystemVersion string | ||
GolangVersion string | ||
} | ||
|
||
// GetBuildInfo returns information about the current build. | ||
func GetBuildInfo() *BuildInfo { | ||
return &BuildInfo{ | ||
buildTime, | ||
lastCommit, | ||
semanticVersion, | ||
systemVersion, | ||
golangVersion, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Show information about the current binary build", | ||
Args: cobra.NoArgs, | ||
Run: printBuildInfo, | ||
} | ||
|
||
func printBuildInfo(_ *cobra.Command, _ []string) { | ||
buildInfo := GetBuildInfo() | ||
fmt.Printf("Semantic version: %s\n", buildInfo.SemanticVersion) | ||
fmt.Printf("Commit: %s\n", buildInfo.LastCommit) | ||
fmt.Printf("Build Date: %s\n", buildInfo.BuildTime) | ||
fmt.Printf("System version: %s\n", buildInfo.SystemVersion) | ||
fmt.Printf("Golang version: %s\n", buildInfo.GolangVersion) | ||
} |