Skip to content

Commit

Permalink
chore: improve main flag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fufuok committed Nov 15, 2024
1 parent 10d7331 commit 17794bf
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions master/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ import (
"github.com/fufuok/pkg/config"
)

var version, daemon bool
var (
// FlagParser 可由 App 指定自定义的 flag
FlagParser = flagParse

Daemon bool
Version bool
)

func flagParse() {
flag.StringVar(&config.RootPath, "p", config.DefaultRootPath, "程序启动目录(可选)")
flag.StringVar(&config.ConfigFile, "c", config.ConfigFile, "主配置文件绝对路径(可选)")
flag.BoolVar(&config.Debug, "debug", false, "全局调试模式, 控制台 DEBUG 日志")
flag.BoolVar(&daemon, "d", false, "启动后台守护进程")
flag.BoolVar(&version, "v", false, "版本信息")
flag.BoolVar(&config.Debug, "debug", config.Debug, "开发者调试模式, 控制台 Debug 日志")
flag.BoolVar(&Daemon, "d", Daemon, "启动后台守护进程")
flag.BoolVar(&Version, "v", Version, "版本信息")
flag.Parse()
}

// Main 带默认命令行参数启动
func Main() {
flagParse()
FlagParser()

if version {
if Version {
fmt.Println(">>>", config.AppName, config.Version, config.GoVersion)
fmt.Println(">>>", config.GitCommit)
return
Expand All @@ -37,7 +43,7 @@ func Main() {

// Run 守护进程启动程序
func Run() {
if daemon && !config.Debug {
if Daemon && !config.Debug {
xdaemon.NewDaemon(config.LogDaemon).Run()
}

Expand Down

0 comments on commit 17794bf

Please sign in to comment.