From 119730badaaad7b6794102886fa2d390cb0944a9 Mon Sep 17 00:00:00 2001 From: fumiama Date: Mon, 11 Oct 2021 13:15:38 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=A2=9E=E5=8A=A0-h=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E4=BC=98=E5=8C=96=E5=8F=82=E6=95=B0=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/web/init.go | 4 +--- main.go | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/control/web/init.go b/control/web/init.go index 95c9c613..7e257e3d 100644 --- a/control/web/init.go +++ b/control/web/init.go @@ -4,10 +4,8 @@ package web import "flag" func init() { - var en bool // 解析命令行参数,输入 `-g` 即可启用 gui - flag.BoolVar(&en, "g", false, "Enable web gui.") - if en { + if *flag.Bool("g", false, "Enable web gui.") { initGui() } } diff --git a/main.go b/main.go index cba89d27..6d77207e 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "os" "strings" // 注:以下插件均可通过前面加 // 注释,注释后停用并不加载插件 @@ -63,32 +64,36 @@ var ( ) func init() { - var ( - debg bool - warn bool - ) - /* 注释处已移动至 control/web - // 解析命令行参数,输入 `-g` 即可启用 gui - flag.BoolVar(&en, "g", false, "Enable web gui.") - */ // 解析命令行参数,输入 `-d` 即可开启 debug log - flag.BoolVar(&debg, "d", false, "Enable debug log and higher level.") - flag.BoolVar(&warn, "w", false, "Enable warning log and higher level.") + d := flag.Bool("d", false, "Enable debug level log and higher.") + w := flag.Bool("w", false, "Enable warning level log and higher.") + h := flag.Bool("h", false, "Display this help.") flag.Parse() - if debg && !warn { - logrus.SetLevel(logrus.DebugLevel) - } - if warn { - logrus.SetLevel(logrus.WarnLevel) + if *h { + printBanner() + fmt.Println("Usage:") + flag.PrintDefaults() + os.Exit(0) + } else { + if *d && !*w { + logrus.SetLevel(logrus.DebugLevel) + } + if *w { + logrus.SetLevel(logrus.WarnLevel) + } } } -func main() { +func printBanner() { fmt.Print( "\n======================[ZeroBot-Plugin]======================", "\n", banner, "\n", "============================================================\n", - ) // 启动打印 + ) +} + +func main() { + printBanner() zero.Run(zero.Config{ NickName: []string{"椛椛", "ATRI", "atri", "亚托莉", "アトリ"}, CommandPrefix: "/",