|
|
|
@ -11,6 +11,7 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/q191201771/naza/pkg/nazalog"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
@ -31,18 +32,41 @@ func parseFlag() string {
|
|
|
|
|
binInfoFlag := flag.Bool("v", false, "show bin info")
|
|
|
|
|
cf := flag.String("c", "", "specify conf file")
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
if *binInfoFlag {
|
|
|
|
|
_, _ = fmt.Fprint(os.Stderr, bininfo.StringifyMultiLine())
|
|
|
|
|
_, _ = fmt.Fprintln(os.Stderr, base.LALFullInfo)
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}
|
|
|
|
|
if *cf == "" {
|
|
|
|
|
flag.Usage()
|
|
|
|
|
_, _ = fmt.Fprintf(os.Stderr, `
|
|
|
|
|
|
|
|
|
|
// 运行参数中有配置文件,直接返回
|
|
|
|
|
if *cf != "" {
|
|
|
|
|
return *cf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 运行参数中没有配置文件,尝试从几个默认位置读取
|
|
|
|
|
nazalog.Warnf("config file not specify in command line, try to load some common config file in common path.")
|
|
|
|
|
defaultConfigFileList := []string{
|
|
|
|
|
filepath.FromSlash("lalserver.conf.json"),
|
|
|
|
|
filepath.FromSlash("./conf/lalserver.conf.json"),
|
|
|
|
|
filepath.FromSlash("../conf/lalserver.conf.json"),
|
|
|
|
|
}
|
|
|
|
|
for _, dcf := range defaultConfigFileList {
|
|
|
|
|
fi, err := os.Stat(dcf)
|
|
|
|
|
if err == nil && fi.Size() > 0 && !fi.IsDir() {
|
|
|
|
|
nazalog.Warnf("%s exist. using it as config file.", dcf)
|
|
|
|
|
return dcf
|
|
|
|
|
} else {
|
|
|
|
|
nazalog.Warnf("%s not exist.", dcf)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 默认位置都没有,退出程序
|
|
|
|
|
flag.Usage()
|
|
|
|
|
_, _ = fmt.Fprintf(os.Stderr, `
|
|
|
|
|
Example:
|
|
|
|
|
%s -c %s
|
|
|
|
|
`, os.Args[0], filepath.FromSlash("./conf/lalserver.conf.json"))
|
|
|
|
|
base.OSExitAndWaitPressIfWindows(1)
|
|
|
|
|
}
|
|
|
|
|
return *cf
|
|
|
|
|
}
|
|
|
|
|