Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Jan 26, 2022
1 parent d327b50 commit 1226af7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import (
"os"
)

var (
buildVersion = ""
buildDate = ""
buildCommit = ""
)

var rootCmd = &cobra.Command{
Use: "go-mlog",
Short: "golang to mlog transpiler",
Expand All @@ -31,7 +37,10 @@ var rootCmd = &cobra.Command{
},
}

func Execute() {
func Execute(version string, date string, commit string) {
buildVersion = version
buildDate = date
buildCommit = commit
if err := rootCmd.Execute(); err != nil {
panic(err)
}
Expand Down
19 changes: 19 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print current go-mlog version",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("%s-%s-%s", buildVersion, buildCommit, buildDate)
return nil
},
}
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import (
_ "github.com/Vilsol/go-mlog/x/impl"
)

var (
// The build version
version = "dev"

// The build commit
commit = "none"

// The build date
date = "unknown"
)

func main() {
cmd.Execute()
cmd.Execute(version, date, commit)
}

0 comments on commit 1226af7

Please sign in to comment.