-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Justin Toh <tohjustin@hotmail.com>
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package version | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
var ( | ||
gitMajor string // major version, always numeric | ||
gitMinor string // minor version, numeric possibly followed by "+" | ||
gitVersion string // semantic version, derived by build scripts | ||
gitCommit string // sha1 from git, output of $(git rev-parse HEAD) | ||
gitTreeState string // state of git tree, either "clean" or "dirty" | ||
buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
) | ||
|
||
// Info defines the version. | ||
type Info struct { | ||
Major string `json:"major,omitempty"` | ||
Minor string `json:"minor,omitempty"` | ||
GitVersion string `json:"gitVersion,omitempty"` | ||
GitCommit string `json:"gitCommit,omitempty"` | ||
GitTreeState string `json:"gitTreeState,omitempty"` | ||
BuildDate string `json:"buildDate,omitempty"` | ||
GoVersion string `json:"goVersion,omitempty"` | ||
Compiler string `json:"compiler,omitempty"` | ||
Platform string `json:"platform,omitempty"` | ||
} | ||
|
||
// Get returns metadata and information regarding the version. | ||
func Get() Info { | ||
return Info{ | ||
Major: gitMajor, | ||
Minor: gitMinor, | ||
GitVersion: gitVersion, | ||
GitCommit: gitCommit, | ||
GitTreeState: gitTreeState, | ||
BuildDate: buildDate, | ||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
} | ||
} | ||
|
||
// String returns info as a human-friendly version string. | ||
func (info Info) String() string { | ||
return info.GitVersion | ||
} |
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,17 @@ | ||
package lineage | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/tohjustin/kube-lineage/internal/version" | ||
) | ||
|
||
func getVersion() string { | ||
return fmt.Sprintf("%#v", version.Get()) | ||
} | ||
|
||
func addVersionFlag(c *cobra.Command) { | ||
c.Version = getVersion() | ||
c.SetVersionTemplate("{{printf \"%s\" .Version}}\n") | ||
} |