Skip to content

Commit

Permalink
fix version
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Luiz committed Feb 29, 2024
1 parent 83be31b commit 1baf54b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ before:

builds:
- main: "./main.go"
ldflags:
- -s -w -X "main.goversion={{.Env.GO_VERSION}}"
- -s -w -X "main.goinitversion={{.Env.GIT_TAG}}"
binary: goinit
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
id: goinit

archives:
- format: tar.gz
Expand Down
29 changes: 24 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"log"
"os"
"runtime"
"runtime/debug"

"github.com/samluiz/goinit/internal/cli"
)
Expand All @@ -18,10 +20,26 @@ const banner string = `
## ## ### ### ## ## ### ## ##
##### ##### ###### ## ## ###### ##`

var (
displayVersion bool
version string
)
var displayVersion bool

func GetVersionInfo() versionInfo {
if len(goinitversion) != 0 && len(goversion) != 0 {
return versionInfo{
goinitversion: goinitversion,
goversion: goversion,
}
}
if info, ok := debug.ReadBuildInfo(); ok {
return versionInfo{
goinitversion: info.Main.Version,
goversion: runtime.Version(),
}
}
return versionInfo{
goinitversion: "(unknown)",
goversion: runtime.Version(),
}
}

func helpMessage() {
fmt.Println("Usage: goinit [flags]")
Expand All @@ -43,9 +61,10 @@ func init() {
}

func main() {
versionInfo := GetVersionInfo()
fmt.Print(banner)
if displayVersion {
fmt.Println(version)
fmt.Printf("\nversion: %s\ngo Version: %s\n", versionInfo.goinitversion, versionInfo.goversion)
return
}
cli.Run(os.Stdin)
Expand Down
8 changes: 8 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

var goinitversion, goversion string

type versionInfo struct {
goinitversion string
goversion string
}

0 comments on commit 1baf54b

Please sign in to comment.