2023-06-15 21:22:51 +08:00
|
|
|
//
|
|
|
|
// cli_list.go
|
|
|
|
// Copyright (C) 2022 tiglog <me@tiglog.com>
|
|
|
|
//
|
|
|
|
// Distributed under terms of the MIT license.
|
|
|
|
//
|
|
|
|
|
2023-10-15 00:54:45 +08:00
|
|
|
package gconsole
|
2023-06-15 21:22:51 +08:00
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
type cList struct {
|
|
|
|
BaseCmd
|
|
|
|
cli IConsole
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewListCmd(cli IConsole) *cList {
|
|
|
|
return &cList{
|
|
|
|
BaseCmd{
|
|
|
|
Name: "list",
|
|
|
|
Desc: "列出支持的命令",
|
|
|
|
},
|
|
|
|
cli,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cList) Init(args []string) {
|
|
|
|
c.Action = func() error {
|
|
|
|
fmt.Printf("Usage: %s <command> [<args>]\n\n%s\n\nCommands:\n", c.cli.GetName(), c.cli.GetDesc())
|
|
|
|
cmds := c.cli.GetCmds()
|
|
|
|
for _, cmd := range cmds {
|
|
|
|
fmt.Printf("%8s: %s\n", cmd.GetName(), cmd.GetDesc())
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cList) GetHelp() string {
|
|
|
|
return c.Desc
|
|
|
|
}
|