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

43 lines
698 B
Go

//
// cli_list.go
// Copyright (C) 2022 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package console
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
}