Skip to content

Commit e2ee3ca

Browse files
committed
fix: use correct version info
1 parent 2a29fef commit e2ee3ca

5 files changed

Lines changed: 56 additions & 5 deletions

File tree

.goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ builds:
2727
ldflags:
2828
- -s -w
2929
- -X main.version={{.Version}}
30-
- -X main.commit={{.Commit}}
31-
- -X main.date={{.CommitTimestamp}}
30+
- -X main.commit={{.ShortCommit}}
31+
- -X main.date={{.CommitDate}}
3232
mod_timestamp: '{{ .CommitTimestamp }}'
3333

3434
# Our binaries are small, so we can skip UPX compression

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tasks:
2626
vars:
2727
LDFLAGS: '-X main.version={{.VERSION}}-dev -X main.commit={{.COMMIT}} -X main.date={{.BUILD_DATE}}'
2828
cmds:
29-
- go run {{.MAIN_PACKAGE}} {{.CLI_ARGS}}
29+
- go run -ldflags "{{.LDFLAGS}}" {{.MAIN_PACKAGE}} {{.CLI_ARGS}}
3030

3131
# Build tasks
3232
build:

cmd/root.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,40 @@ import (
77
"github.com/spf13/cobra"
88
)
99

10+
// Version info populated by main.go from ldflags
11+
var (
12+
buildVersion = "dev"
13+
buildCommit = "unknown"
14+
buildDate = "unknown"
15+
)
16+
17+
// SetVersionInfo is called by main.go to populate version information
18+
func SetVersionInfo(version, commit, date string) {
19+
buildVersion = version
20+
buildCommit = commit
21+
buildDate = date
22+
}
23+
24+
// GetVersion returns the semantic version string
25+
func GetVersion() string {
26+
return buildVersion
27+
}
28+
29+
// GetCommit returns the git commit hash
30+
func GetCommit() string {
31+
return buildCommit
32+
}
33+
34+
// GetDate returns the build date
35+
func GetDate() string {
36+
return buildDate
37+
}
38+
39+
// IsDebugBuild returns true if this is a dev build (not set via ldflags)
40+
func IsDebugBuild() bool {
41+
return buildVersion == "dev"
42+
}
43+
1044
func init() {
1145

1246
}

cmd/version.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ func init() {
1414
var versionCmd = &cobra.Command{
1515
Use: "version",
1616
Short: "Print the version number",
17-
Long: "Shows all the necessary version information for bug reports.",
17+
Long: "Shows version information for BetterDiscord CLI.",
1818
Run: func(cmd *cobra.Command, args []string) {
19-
fmt.Println(debug.ReadBuildInfo())
19+
// Show clean output for production builds, debug info for dev builds
20+
if IsDebugBuild() {
21+
fmt.Println(debug.ReadBuildInfo())
22+
} else {
23+
fmt.Printf("BetterDiscord CLI %s\n", GetVersion())
24+
fmt.Printf("Commit: %s\n", GetCommit())
25+
fmt.Printf("Built: %s\n", GetDate())
26+
}
2027
},
2128
}
29+

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ import (
66
"github.com/betterdiscord/cli/cmd"
77
)
88

9+
// Version information set by ldflags during build
10+
var (
11+
version = "dev" // Set by: -X main.version=v1.0.0
12+
commit = "unknown" // Set by: -X main.commit=abc123
13+
date = "unknown" // Set by: -X main.date=2025-02-15...
14+
)
15+
916
func main() {
1017
log.SetFlags(0)
18+
// Initialize version info for cmd package
19+
cmd.SetVersionInfo(version, commit, date)
1120
cmd.Execute()
1221
}

0 commit comments

Comments
 (0)