Skip to content

Commit

Permalink
feat: improve version command
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Sep 7, 2022
1 parent 5ca7e9e commit 4ea42aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
11 changes: 4 additions & 7 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"os"
"strings"
)

// Version will be set at build time
Expand All @@ -14,6 +13,9 @@ var Version string
// CommitHash will be set at build time
var CommitHash string

// RepositoryStatus will be set at build time
var RepositoryStatus string

// BuildAt will be set at build time
var BuildAt string

Expand All @@ -25,15 +27,10 @@ func init() {
// Only log the warning severity or above.
zerolog.SetGlobalLevel(zerolog.WarnLevel)

// detect debug mode
debugValue, debugIsSet := os.LookupEnv("NCI_DEBUG")
if debugIsSet && strings.EqualFold(debugValue, "true") {
zerolog.SetGlobalLevel(zerolog.TraceLevel)
}

// version information
cmd.Version = Version
cmd.CommitHash = CommitHash
cmd.RepositoryStatus = RepositoryStatus
cmd.BuildAt = BuildAt
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"
"runtime"

"github.com/spf13/cobra"
Expand All @@ -13,6 +14,9 @@ var Version string
// CommitHash will be set at build time
var CommitHash string

// RepositoryStatus will be set at build time
var RepositoryStatus string

// BuildAt will be set at build time
var BuildAt string

Expand All @@ -24,6 +28,12 @@ var versionCmd = &cobra.Command{
Use: "version",
Long: "Prints the version number of reposync",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("reposync v" + Version + "-" + CommitHash + " " + runtime.GOOS + "/" + runtime.GOARCH + " BuildDate=" + BuildAt)
fmt.Fprintf(os.Stdout, "GitVersion: %s\n", Version)
fmt.Fprintf(os.Stdout, "GitCommit: %s\n", CommitHash)
fmt.Fprintf(os.Stdout, "GitTreeState: %s\n", RepositoryStatus)
fmt.Fprintf(os.Stdout, "BuildDate: %s\n", BuildAt)
fmt.Fprintf(os.Stdout, "GoVersion: %s\n", runtime.Version())
fmt.Fprintf(os.Stdout, "Compiler: %s\n", runtime.Compiler)
fmt.Fprintf(os.Stdout, "Platform: %s\n", runtime.GOOS+"/"+runtime.GOARCH)
},
}

0 comments on commit 4ea42aa

Please sign in to comment.