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
+9 -1
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)
}
}