Skip to content

Commit

Permalink
chore: adjust the version (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenquan authored Apr 30, 2023
1 parent 30cb982 commit 33dd683
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"math"
"os"
"runtime"
"runtime/debug"

"github.com/chenquan/diskusage/internal"
"github.com/spf13/cobra"
Expand All @@ -44,10 +45,27 @@ var rootCmd = &cobra.Command{
GitHub: https://github.com/chenquan/diskusage
Issues: https://github.com/chenquan/diskusage/issues`,
RunE: internal.Stat,
Version: fmt.Sprintf(
"%s %s/%s %s", BuildVersion,
runtime.GOOS, runtime.GOARCH, runtime.Version()),
RunE: internal.Stat,
Version: getVersion(),
}

func getVersion() string {
buildVersion := BuildVersion

buildInfo, ok := debug.ReadBuildInfo()
if ok {
for _, setting := range buildInfo.Settings {
if setting.Key == "vcs.revision" {
buildVersion = fmt.Sprintf("%s(%s)", buildVersion, setting.Value)
break
}
}
}

return fmt.Sprintf(
"%s %s/%s %s", buildVersion,
runtime.GOOS, runtime.GOARCH, runtime.Version())

}

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

0 comments on commit 33dd683

Please sign in to comment.