fix(version): command line flag

This commit is contained in:
2024-03-30 00:37:51 +00:00
parent 3bdca8c540
commit 6092629cb4
4 changed files with 18 additions and 7 deletions

View File

@@ -79,7 +79,6 @@ type CronSchedule struct {
func SetVersion(version string) {
version = strings.TrimRight(version, versionTrimRightCutSet)
viper.Set(WingmateVersion, version)
wingmate.Log().Info().Msgf("starting wingmate version %s", version)
}
func Read() (*Config, error) {
@@ -91,8 +90,6 @@ func Read() (*Config, error) {
viper.SetDefault(PidProxyPathConfig, PidProxyPathDefault)
viper.SetDefault(ExecPathConfig, ExecPathDefault)
ParseFlags()
var (
dirent []os.DirEntry
err error

View File

@@ -1,12 +1,15 @@
package config
import (
"fmt"
"os"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
func ParseFlags() {
pflag.BoolP(VersionFlag, "v", false, "check version")
pflag.CountP(VersionFlag, "v", "check version")
pflag.String(WMPidProxyPathFlag, "", "wmpidproxy path")
pflag.String(WMExecPathFlag, "", "wmexec path")
pflag.StringP(ConfigPathFlag, "c", "", "config path")
@@ -17,4 +20,9 @@ func ParseFlags() {
_ = viper.BindPFlag(ConfigPath, pflag.CommandLine.Lookup(ConfigPathFlag))
_ = viper.BindPFlag(PidProxyPathConfig, pflag.CommandLine.Lookup(WMPidProxyPathFlag))
_ = viper.BindPFlag(ExecPathConfig, pflag.CommandLine.Lookup(WMExecPathFlag))
if viper.GetInt(VersionCheckKey) > 0 {
fmt.Println(viper.GetString(WingmateVersion))
os.Exit(0)
}
}