File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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 :
Original file line number Diff line number Diff 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+
1044func init () {
1145
1246}
Original file line number Diff line number Diff line change @@ -14,8 +14,16 @@ func init() {
1414var 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+
Original file line number Diff line number Diff 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+
916func main () {
1017 log .SetFlags (0 )
18+ // Initialize version info for cmd package
19+ cmd .SetVersionInfo (version , commit , date )
1120 cmd .Execute ()
1221}
You can’t perform that action at this time.
0 commit comments