Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --version option to the rootCmd #301

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd

import (
"fmt"
"log/slog"
"os"
"runtime/debug"
"strings"

"github.com/resonatehq/resonate/cmd/dst"
Expand All @@ -17,11 +19,27 @@ import (

var (
server, cfgFile string
Version string = "dev"
)

func computeVersion() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check out the link i sent before, i'll paste here again: https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications

this whole function is not needed.

buildInfo, buildInfoRead := debug.ReadBuildInfo()
var commitHash = "dev"
if buildInfoRead {
for _, setting := range buildInfo.Settings {
if setting.Key == "vcs.revision" {
commitHash = setting.Value
break
}
}
}
return fmt.Sprintf("%s (%s)", Version, commitHash)
}

var rootCmd = &cobra.Command{
Use: "resonate",
Short: "Durable promises",
Use: "resonate",
Short: "Durable promises",
Version: computeVersion(),
}

func init() {
Expand Down