blackstork-io / fabric

An open-source command-line tool for reporting workflow automation and a configuration language for reusable templates. Reporting-as-Code
https://blackstork.io/fabric/
Apache License 2.0
12 stars 0 forks source link

Fix CLI version when installed it using `go` #119

Closed dobarx closed 1 month ago

dobarx commented 3 months ago

Fabric CLI can already be installed using go command:

$ go install github.com/blackstork-io/fabric@latest
# or
$ go install github.com/blackstork-io/fabric@v0.4.0-rev0

But the version is always set to:

$ fabric --version
fabric version v0.0.0-dev

We can use runtime/debug std package and retrieve main module version. For example:

package main

import "runtime/debug"

var version string

func main() {
    // ...
}
func init() {
   info, ok :=  debug.ReadBuildInfo()
   if !ok {
      version = "0.0.0-dev"
      return
   }
   version = info.Main.Version
}

More info: https://pkg.go.dev/runtime/debug#ReadBuildInfo