Skip to content

Commit 33dd683

Browse files
authored
chore: adjust the version (#84)
1 parent 30cb982 commit 33dd683

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

cmd/root.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"math"
2020
"os"
2121
"runtime"
22+
"runtime/debug"
2223

2324
"github.com/chenquan/diskusage/internal"
2425
"github.com/spf13/cobra"
@@ -44,10 +45,27 @@ var rootCmd = &cobra.Command{
4445
4546
GitHub: https://github.com/chenquan/diskusage
4647
Issues: https://github.com/chenquan/diskusage/issues`,
47-
RunE: internal.Stat,
48-
Version: fmt.Sprintf(
49-
"%s %s/%s %s", BuildVersion,
50-
runtime.GOOS, runtime.GOARCH, runtime.Version()),
48+
RunE: internal.Stat,
49+
Version: getVersion(),
50+
}
51+
52+
func getVersion() string {
53+
buildVersion := BuildVersion
54+
55+
buildInfo, ok := debug.ReadBuildInfo()
56+
if ok {
57+
for _, setting := range buildInfo.Settings {
58+
if setting.Key == "vcs.revision" {
59+
buildVersion = fmt.Sprintf("%s(%s)", buildVersion, setting.Value)
60+
break
61+
}
62+
}
63+
}
64+
65+
return fmt.Sprintf(
66+
"%s %s/%s %s", buildVersion,
67+
runtime.GOOS, runtime.GOARCH, runtime.Version())
68+
5169
}
5270

5371
// Execute adds all child commands to the root command and sets flags appropriately.

0 commit comments

Comments
 (0)