From d31bbf922682ceb120c16b32a320d1f7c13b2cfc Mon Sep 17 00:00:00 2001 From: wweir Date: Wed, 27 Mar 2019 21:22:52 +0800 Subject: [PATCH] Fix #12, add print version flag --- conf/conf.go | 1 + conf/conf_other.go | 1 + conf/conf_windows.go | 6 ++++-- main.go | 5 +++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/conf/conf.go b/conf/conf.go index 6c2168d..5cf08b9 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -36,6 +36,7 @@ var Conf = struct { WhiteList []string `toml:"whitelist"` Suggestions []string `toml:"suggestions"` Verbose int `toml:"verbose"` + VersionOnly bool `toml:"-"` }{} func init() { diff --git a/conf/conf_other.go b/conf/conf_other.go index b67a19e..43eb08d 100644 --- a/conf/conf_other.go +++ b/conf/conf_other.go @@ -24,6 +24,7 @@ func initArgs() { flag.StringVar(&Conf.DNSServer, "d", "114.114.114.114", "client dns server") flag.StringVar(&Conf.ClientIP, "c", "127.0.0.1", "client dns service redirect IP") flag.StringVar(&Conf.SuggestLevel, "S", "SPEEDUP", "suggest level setting: "+strings.Join(dns.ListSuggestLevels(), ",")) + flag.BoolVar(&Conf.VersionOnly, "V", false, "print sower version") if !flag.Parsed() { flag.Set("logtostderr", "true") diff --git a/conf/conf_windows.go b/conf/conf_windows.go index 77495dc..f9c08c2 100644 --- a/conf/conf_windows.go +++ b/conf/conf_windows.go @@ -21,12 +21,14 @@ const name = "sower" const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue func initArgs() { - flag.StringVar(&Conf.ConfigFile, "f", filepath.Dir(os.Args[0])+"/sower.toml", "config file location") + flag.StringVar(&Conf.ConfigFile, "f", filepath.Dir(os.Args[0])+"\\sower.toml", "config file location") + flag.BoolVar(&Conf.VersionOnly, "V", false, "print sower version") install := flag.Bool("install", false, "install sower as a service") uninstall := flag.Bool("uninstall", false, "uninstall sower from service list") if !flag.Parsed() { - flag.Set("log_dir", filepath.Dir(os.Args[0])) + os.Mkdir("log", 0755) + flag.Set("log_dir", filepath.Dir(os.Args[0])+"/log") flag.Parse() } diff --git a/main.go b/main.go index 636e05c..156ad80 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net" "github.com/golang/glog" @@ -14,6 +15,10 @@ var version, date string func main() { cfg := &conf.Conf + if cfg.VersionOnly { + fmt.Printf("Version: %s %s config: %v", version, date, cfg) + return + } glog.Infof("Starting sower(%s %s): %v", version, date, cfg) tran, err := transport.GetTransport(cfg.NetType)