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:
Csaba Maulis
2023-07-11 13:54:42 +08:00
committed by GitHub
parent 969af2ab69
commit 0c0ba19a23
8 changed files with 79 additions and 64 deletions

View File

@@ -13,6 +13,7 @@ import (
"golang.org/x/sys/cpu"
"github.com/stashapp/stash/internal/build"
"github.com/stashapp/stash/pkg/logger"
)
@@ -170,7 +171,7 @@ func GetLatestRelease(ctx context.Context) (*LatestRelease, error) {
wantedRelease := stashReleases()[platform]
url := apiReleases
if IsDevelop() {
if build.IsDevelop() {
// get the release tagged with the development tag
url += "/tags/" + developmentTag
} else {
@@ -213,7 +214,7 @@ func GetLatestRelease(ctx context.Context) (*LatestRelease, error) {
}
}
_, githash, _ := GetVersion()
_, githash, _ := build.Version()
shLength := len(githash)
if shLength == 0 {
shLength = defaultSHLength
@@ -273,7 +274,7 @@ func printLatestVersion(ctx context.Context) {
if err != nil {
logger.Errorf("Couldn't retrieve latest version: %v", err)
} else {
_, githash, _ = GetVersion()
_, githash, _ := build.Version()
switch {
case githash == "":
logger.Infof("Latest version: %s (%s)", latestRelease.Version, latestRelease.ShortHash)