golib/console/cli_help.go
2023-06-15 21:22:51 +08:00

48 lines
665 B
Go

//
// cli_help.go
// Copyright (C) 2022 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package console
import (
"errors"
"fmt"
)
type cHelp struct {
BaseCmd
cli IConsole
}
func NewHelpCmd(cli IConsole) *cHelp {
return &cHelp{
BaseCmd{
Name: "help",
Desc: "查看命令的使用方法",
},
cli,
}
}
func (c *cHelp) Init(args []string) {
if len(args) == 0 {
return
}
c.Action = func() error {
cmds := c.cli.GetCmds()
cmd, ok := cmds[args[0]]
if !ok {
return errors.New("指定的命令不存在")
}
fmt.Println(cmd.GetHelp())
return nil
}
}
func (c *cHelp) GetHelp() string {
return c.Desc
}