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

@@ -11,6 +11,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/stashapp/stash/internal/build"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
)
@@ -25,6 +26,7 @@ type flagStruct struct {
cpuProfilePath string
nobrowser bool
helpFlag bool
versionFlag bool
}
func GetInstance() *Instance {
@@ -47,6 +49,11 @@ func Initialize() (*Instance, error) {
os.Exit(0)
}
if flags.versionFlag {
fmt.Printf(build.VersionString() + "\n")
os.Exit(0)
}
overrides := makeOverrideConfig()
_ = GetInstance()
@@ -134,6 +141,7 @@ func initFlags() flagStruct {
pflag.StringVar(&flags.cpuProfilePath, "cpuprofile", "", "write cpu profile to file")
pflag.BoolVar(&flags.nobrowser, "nobrowser", false, "Don't open a browser window after launch")
pflag.BoolVarP(&flags.helpFlag, "help", "h", false, "show this help text and exit")
pflag.BoolVarP(&flags.versionFlag, "version", "v", false, "show version number and exit")
pflag.Parse()