File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
4546GitHub: https://github.com/chenquan/diskusage
4647Issues: 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.
You can’t perform that action at this time.
0 commit comments