Skip to content

Commit

Permalink
Fix #12, add print version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir committed Mar 27, 2019
1 parent ac4e426 commit d31bbf9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var Conf = struct {
WhiteList []string `toml:"whitelist"`
Suggestions []string `toml:"suggestions"`
Verbose int `toml:"verbose"`
VersionOnly bool `toml:"-"`
}{}

func init() {
Expand Down
1 change: 1 addition & 0 deletions conf/conf_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions conf/conf_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"net"

"github.com/golang/glog"
Expand All @@ -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)
Expand Down

0 comments on commit d31bbf9

Please sign in to comment.