2022-11-24 23:37:34 +08:00
|
|
|
|
// Package cmd
|
|
|
|
|
// @Link https://github.com/bufanyun/hotgo
|
2023-02-23 17:53:04 +08:00
|
|
|
|
// @Copyright Copyright (c) 2023 HotGo CLI
|
2022-11-24 23:37:34 +08:00
|
|
|
|
// @Author Ms <133814250@qq.com>
|
|
|
|
|
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
|
"github.com/gogf/gf/v2/os/gcmd"
|
|
|
|
|
"hotgo/internal/library/casbin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
Tools = &gcmd.Command{
|
|
|
|
|
Name: "tools",
|
2023-05-10 23:54:50 +08:00
|
|
|
|
Brief: "常用工具",
|
2022-11-24 23:37:34 +08:00
|
|
|
|
Description: ``,
|
|
|
|
|
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
|
|
|
|
flags := parser.GetOptAll()
|
2023-05-07 22:35:29 +08:00
|
|
|
|
g.Log().Debugf(ctx, "flags:%+v", flags)
|
2022-11-24 23:37:34 +08:00
|
|
|
|
if len(flags) == 0 {
|
|
|
|
|
g.Log().Fatal(ctx, "工具参数不能为空")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
method, ok := flags["m"]
|
|
|
|
|
if !ok {
|
|
|
|
|
g.Log().Fatal(ctx, "工具方法不能为空")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch method {
|
|
|
|
|
case "casbin":
|
|
|
|
|
a1, ok := flags["a1"]
|
|
|
|
|
if !ok {
|
|
|
|
|
g.Log().Fatal(ctx, "casbin参数不能为空")
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-05-10 23:54:50 +08:00
|
|
|
|
casbin.InitEnforcer(ctx)
|
2022-11-24 23:37:34 +08:00
|
|
|
|
if a1 == "clear" {
|
|
|
|
|
if err := casbin.Clear(ctx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
} else if a1 == "refresh" {
|
|
|
|
|
if err := casbin.Refresh(ctx); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
g.Log().Fatalf(ctx, "casbin参数无效,a1:%+v", a1)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
g.Log().Fatal(ctx, "工具方法不存在")
|
|
|
|
|
}
|
|
|
|
|
g.Log().Info(ctx, "执行完成!")
|
|
|
|
|
return
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
)
|