Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
cmd参数解析优化
Browse files Browse the repository at this point in the history
  • Loading branch information
hb-chen committed May 22, 2018
1 parent 0031def commit be7bf7c
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ package main

import (
"flag"
"fmt"

"github.com/hb-go/echo-web/module/log"
"github.com/hb-go/echo-web/router"
)

var helpInfo = "help\n -h 帮助\n -c conf/conf.toml 配置文件路径,默认conf/conf.toml\n"
var cmdConf = flag.Bool("c", false, "配置文件路径")
var cmdHelp = flag.Bool("h", false, "帮助")
const (
DefaultConfFilePath = "conf/conf.toml"
)

var (
confFilePath string
cmdHelp bool
)

func init() {
flag.StringVar(&confFilePath, "c", DefaultConfFilePath, "配置文件路径")
flag.BoolVar(&cmdHelp, "h", false, "帮助")
flag.Parse()

}

func main() {
confFilePath := "" // 默认conf/conf.toml

//解析命令行标志
flag.Parse() // Scans the arg list and sets up flags
if *cmdConf {
if flag.NArg() == 1 {
confFilePath = flag.Arg(0)
log.Debugf("run with conf:%s", confFilePath)
} else {
fmt.Printf("-c 参数错误\n" + helpInfo)
return
}
} else if *cmdHelp {
fmt.Printf(helpInfo)
if cmdHelp {
flag.PrintDefaults()
return
}
log.Debugf("run with conf:%s", confFilePath)

// 子域名部署
router.RunSubdomains(confFilePath)
Expand Down

0 comments on commit be7bf7c

Please sign in to comment.