Skip to content

Commit

Permalink
Change version string format and add VendorInfo to help with issue tr…
Browse files Browse the repository at this point in the history
…iaging

* Change version string format as proposed by @moorereason

 1. shorten program name
 2. make version string semver compliant with +extended.
    The slash is not allowed in semver.
 3. Use key=value pairs for BuildDate etc.

* Add optional vendorInfo to version string

to help with issue triaging, e.g. VendorInfo=debian:0.80.0-7
  • Loading branch information
anthonyfok authored Feb 16, 2021
1 parent 3a5ee0d commit e8df097
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions common/hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ var (

// buildDate contains the date of the current build.
buildDate string

// vendorInfo contains vendor notes about the current build.
vendorInfo string
)

// Info contains information about the current Hugo environment
Expand Down
14 changes: 11 additions & 3 deletions common/hugo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ func (v Version) NextPatchLevel(level int) Version {
// BuildVersionString creates a version string. This is what you see when
// running "hugo version".
func BuildVersionString() string {
program := "Hugo Static Site Generator"
// program := "Hugo Static Site Generator"
program := "hugo"

version := "v" + CurrentVersion.String()
if commitHash != "" {
version += "-" + strings.ToUpper(commitHash)
}
if IsExtended {
version += "/extended"
version += "+extended"
}

osArch := runtime.GOOS + "/" + runtime.GOARCH
Expand All @@ -144,7 +145,14 @@ func BuildVersionString() string {
date = "unknown"
}

return fmt.Sprintf("%s %s %s BuildDate: %s", program, version, osArch, date)
versionString := fmt.Sprintf("%s %s %s BuildDate=%s",
program, version, osArch, date)

if vendorInfo != "" {
versionString += " VendorInfo=" + vendorInfo
}

return versionString
}

func version(version float32, patchVersion int, suffix string) string {
Expand Down

0 comments on commit e8df097

Please sign in to comment.