Skip to content

Commit

Permalink
Merge pull request #162 from ninech/fix-dev-version-display
Browse files Browse the repository at this point in the history
fix displaying of nctl version
  • Loading branch information
thirdeyenick authored Sep 18, 2024
2 parents c19c15f + 31172c0 commit 91f0035
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"os/signal"
"runtime/debug"
"strings"
"syscall"

Expand Down Expand Up @@ -50,10 +51,15 @@ type rootCommand struct {
}

const (
version = "dev"
defaultAPICluster = "nineapis.ch"
)

var (
version string
commit string
date string
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -171,7 +177,7 @@ func setupSignalHandler(ctx context.Context, cancel context.CancelFunc) {
// checks for variables which would overwrite already existing ones.
func kongVariables() (kong.Vars, error) {
result := make(kong.Vars)
result["version"] = version
result["version"] = fmt.Sprintf("%s (commit: %s, date: %s)", version, commit, date)
result["api_cluster"] = defaultAPICluster
appCreateKongVars, err := create.ApplicationKongVars()
if err != nil {
Expand All @@ -197,3 +203,23 @@ func merge(existing kong.Vars, withs ...kong.Vars) error {

return nil
}

func init() {
info, ok := debug.ReadBuildInfo()
if !ok {
return
}

if version == "" {
version = info.Main.Version
}

for _, kv := range info.Settings {
switch kv.Key {
case "vcs.revision":
commit = kv.Value
case "vcs.time":
date = kv.Value
}
}
}

0 comments on commit 91f0035

Please sign in to comment.