1 Star 0 Fork 1

yss930819/gf-ex

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cmd_help.go 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
yss930819 提交于 2022-10-08 14:30 . feat: 完成部分库的迁移工作
package yscmd
import (
"context"
"gitee.com/kmyss/gf-ex/yslog"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
)
const CMD_HELP = "help"
type CmdHelpBuilder struct {
CommandBuilderCore
}
func (b *CmdHelpBuilder) SetFlag(builder IFlagBuilder, _ ...string) bool {
return false
}
func (b *CmdHelpBuilder) Init(ctx context.Context) {
b.CommandBuilderCore.Init(ctx)
b.C.Run = b.run
b.C.Use = CMD_HELP
b.C.Short = "显示帮助信息"
}
func (b *CmdHelpBuilder) SetChildCommand(builder ICommandBuilder) bool {
return false
}
func (b *CmdHelpBuilder) run(c *Command) {
yslog.Debug("CmdHelpBuilder Run")
args := gcmd.GetArgAll()
cmdStr := ""
for i, arg := range args {
if arg == CMD_HELP {
cmdStr = gcmd.GetArg(i + 1).String()
}
}
if g.IsEmpty(cmdStr) {
c.parent.ShowHelp()
} else {
cmd := c.parent.commands.Get(cmdStr)
if !g.IsEmpty(cmd) {
cmd.(*Command).ShowHelp()
} else {
yslog.Errorf("%s 命令不存在!", cmdStr)
c.parent.ShowHelp()
}
}
}
func CmdHelp(ctx context.Context) *Command {
b := CmdHelpBuilder{}
b.Init(ctx)
return b.Command()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kmyss/gf-ex.git
git@gitee.com:kmyss/gf-ex.git
kmyss
gf-ex
gf-ex
v0.9.0

搜索帮助