-
Notifications
You must be signed in to change notification settings - Fork 93
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
1 parent
1d3831f
commit 9c4fa8a
Showing
8 changed files
with
174 additions
and
7 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,23 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/replicatedhq/troubleshoot/pkg/version" | ||
) | ||
|
||
func VersionCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the current version and exit", | ||
Long: `Print the current version and exit`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
fmt.Printf("Replicated Preflight %s\n", version.Version()) | ||
|
||
return nil | ||
}, | ||
} | ||
return cmd | ||
} |
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,7 @@ | ||
package version | ||
|
||
// NOTE: these variables are injected at build time | ||
|
||
var ( | ||
version, gitSHA, buildTime string | ||
) |
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,12 @@ | ||
package version | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
var RunAt time.Time | ||
|
||
func init() { | ||
RunAt = time.Now().UTC() | ||
initBuild() | ||
} |
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,72 @@ | ||
package version | ||
|
||
import ( | ||
"runtime" | ||
"time" | ||
) | ||
|
||
var ( | ||
build Build | ||
) | ||
|
||
// Build holds details about this build of the binary | ||
type Build struct { | ||
Version string `json:"version,omitempty"` | ||
GitSHA string `json:"git,omitempty"` | ||
BuildTime time.Time `json:"buildTime,omitempty"` | ||
TimeFallback string `json:"buildTimeFallback,omitempty"` | ||
GoInfo GoInfo `json:"go,omitempty"` | ||
RunAt *time.Time `json:"runAt,omitempty"` | ||
} | ||
|
||
type GoInfo struct { | ||
Version string `json:"version,omitempty"` | ||
Compiler string `json:"compiler,omitempty"` | ||
OS string `json:"os,omitempty"` | ||
Arch string `json:"arch,omitempty"` | ||
} | ||
|
||
// initBuild sets up the version info from build args | ||
func initBuild() { | ||
build.Version = version | ||
if len(gitSHA) >= 7 { | ||
build.GitSHA = gitSHA[:7] | ||
} | ||
var err error | ||
build.BuildTime, err = time.Parse(time.RFC3339, buildTime) | ||
if err != nil { | ||
build.TimeFallback = buildTime | ||
} | ||
|
||
build.GoInfo = getGoInfo() | ||
build.RunAt = &RunAt | ||
} | ||
|
||
// GetBuild gets the build | ||
func GetBuild() Build { | ||
return build | ||
} | ||
|
||
// Version gets the version | ||
func Version() string { | ||
return build.Version | ||
} | ||
|
||
// GitSHA gets the gitsha | ||
func GitSHA() string { | ||
return build.GitSHA | ||
} | ||
|
||
// BuildTime gets the build time | ||
func BuildTime() time.Time { | ||
return build.BuildTime | ||
} | ||
|
||
func getGoInfo() GoInfo { | ||
return GoInfo{ | ||
Version: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
OS: runtime.GOOS, | ||
Arch: runtime.GOARCH, | ||
} | ||
} |