增加-h参数,优化参数处理

This commit is contained in:
fumiama 2021-10-11 13:15:38 +08:00
parent c46748524a
commit 119730bada
2 changed files with 23 additions and 20 deletions

View File

@ -4,10 +4,8 @@ package web
import "flag" import "flag"
func init() { func init() {
var en bool
// 解析命令行参数,输入 `-g` 即可启用 gui // 解析命令行参数,输入 `-g` 即可启用 gui
flag.BoolVar(&en, "g", false, "Enable web gui.") if *flag.Bool("g", false, "Enable web gui.") {
if en {
initGui() initGui()
} }
} }

39
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"os"
"strings" "strings"
// 注:以下插件均可通过前面加 // 注释,注释后停用并不加载插件 // 注:以下插件均可通过前面加 // 注释,注释后停用并不加载插件
@ -63,32 +64,36 @@ var (
) )
func init() { func init() {
var (
debg bool
warn bool
)
/* 注释处已移动至 control/web
// 解析命令行参数,输入 `-g` 即可启用 gui
flag.BoolVar(&en, "g", false, "Enable web gui.")
*/
// 解析命令行参数,输入 `-d` 即可开启 debug log // 解析命令行参数,输入 `-d` 即可开启 debug log
flag.BoolVar(&debg, "d", false, "Enable debug log and higher level.") d := flag.Bool("d", false, "Enable debug level log and higher.")
flag.BoolVar(&warn, "w", false, "Enable warning log and higher level.") w := flag.Bool("w", false, "Enable warning level log and higher.")
h := flag.Bool("h", false, "Display this help.")
flag.Parse() flag.Parse()
if debg && !warn { if *h {
logrus.SetLevel(logrus.DebugLevel) printBanner()
} fmt.Println("Usage:")
if warn { flag.PrintDefaults()
logrus.SetLevel(logrus.WarnLevel) os.Exit(0)
} else {
if *d && !*w {
logrus.SetLevel(logrus.DebugLevel)
}
if *w {
logrus.SetLevel(logrus.WarnLevel)
}
} }
} }
func main() { func printBanner() {
fmt.Print( fmt.Print(
"\n======================[ZeroBot-Plugin]======================", "\n======================[ZeroBot-Plugin]======================",
"\n", banner, "\n", "\n", banner, "\n",
"============================================================\n", "============================================================\n",
) // 启动打印 )
}
func main() {
printBanner()
zero.Run(zero.Config{ zero.Run(zero.Config{
NickName: []string{"椛椛", "ATRI", "atri", "亚托莉", "アトリ"}, NickName: []string{"椛椛", "ATRI", "atri", "亚托莉", "アトリ"},
CommandPrefix: "/", CommandPrefix: "/",