Skip to content

Commit

Permalink
versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickcping committed Aug 27, 2024
1 parent 3e8db74 commit d2d8b84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ builds:
- -trimpath
main: ./main.go
ldflags:
- '-s -w -X "github.com/patrickcping/dvtf-pingctl/cmd/version={{.Version}}" -X "github.com/patrickcping/dvtf-pingctl/cmd/commit={{.Commit}}"'
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
Expand Down
12 changes: 7 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var (
)

const (
jsonFilePathConfigKey = "jsonFilePath"
jsonFilePathParamNameLong = "export-file-path"
jsonFilePathConfigKey = "jsonFilePath"
jsonFilePathParamNameLong = "export-file-path"
jsonFilePathParamNameShort = "e"
)

Expand All @@ -32,7 +32,7 @@ var (
jsonContents string

rootConfigurationParamMapping = map[string]string{
jsonFilePathParamNameLong: jsonFilePathConfigKey,
jsonFilePathParamNameLong: jsonFilePathConfigKey,
}
)

Expand Down Expand Up @@ -80,7 +80,9 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(versionP, commitP string) {
version = versionP
commit = commitP
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand All @@ -101,7 +103,7 @@ func init() {
if err := rootCmd.MarkPersistentFlagRequired(jsonFilePathParamNameLong); err != nil {
l.Err(err).Msgf("Error marking flag %s as required.", jsonFilePathParamNameLong)
}

if err := bindParams(rootConfigurationParamMapping, rootCmd); err != nil {
l.Err(err).Msgf("Error binding parameters: %s", err)
}
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import (
"github.com/patrickcping/dvtf-pingctl/internal/logger"
)

var (
// these will be set by the goreleaser configuration
// to appropriate values for the compiled binary
version string = "dev"

// goreleaser can also pass the specific commit if you want
commit string = ""
)

func main() {
l := logger.Get()

l.Debug().Msg("Starting dvtf")

cmd.Execute()
cmd.Execute(version, commit)
}

0 comments on commit d2d8b84

Please sign in to comment.