mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Add -v/--version flag to print version string (#3883)
* Add `-v/--version` flag to print version string - Created a new flag `-v/--version` in the command-line interface to display the version number and exit. - Moved all version-related functions inside the config package to the new file `manager/config/version.go` to avoid circular dependencies. - Added a new `GetVersionString()` function to generate a formatted version string. - Updated references to the moved version functions. - Updated references in the `Makefile`. * Move version embeds to build package * Remove githash var --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
57
internal/build/version.go
Normal file
57
internal/build/version.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var version string
|
||||
var buildstamp string
|
||||
var githash string
|
||||
var officialBuild string
|
||||
|
||||
func Version() (string, string, string) {
|
||||
return version, githash, buildstamp
|
||||
}
|
||||
|
||||
func VersionString() string {
|
||||
var versionString string
|
||||
switch {
|
||||
case version != "":
|
||||
if githash != "" && !IsDevelop() {
|
||||
versionString = version + " (" + githash + ")"
|
||||
} else {
|
||||
versionString = version
|
||||
}
|
||||
case githash != "":
|
||||
versionString = githash
|
||||
default:
|
||||
versionString = "unknown"
|
||||
}
|
||||
if IsOfficial() {
|
||||
versionString += " - Official Build"
|
||||
} else {
|
||||
versionString += " - Unofficial Build"
|
||||
}
|
||||
if buildstamp != "" {
|
||||
versionString += " - " + buildstamp
|
||||
}
|
||||
return versionString
|
||||
}
|
||||
|
||||
func IsOfficial() bool {
|
||||
return officialBuild == "true"
|
||||
}
|
||||
|
||||
func IsDevelop() bool {
|
||||
if githash == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
// if the version is suffixed with -x-xxxx, then we are running a development build
|
||||
develop := false
|
||||
re := regexp.MustCompile(`-\d+-g\w+$`)
|
||||
if re.MatchString(version) {
|
||||
develop = true
|
||||
}
|
||||
return develop
|
||||
}
|
||||
Reference in New Issue
Block a user