refactor: Console App 需要暴露出去, 自动注册 gen cmd
This commit is contained in:
parent
73642be12c
commit
29e12c1aa6
@ -12,7 +12,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type sApp struct {
|
||||
type ConsoleApp struct {
|
||||
name string
|
||||
version string
|
||||
desc string
|
||||
@ -20,8 +20,8 @@ type sApp struct {
|
||||
about ActionHandler
|
||||
}
|
||||
|
||||
func New(name, desc string) *sApp {
|
||||
app := &sApp{
|
||||
func New(name, desc string) *ConsoleApp {
|
||||
app := &ConsoleApp{
|
||||
name: name,
|
||||
version: "v0.1.0",
|
||||
desc: desc,
|
||||
@ -29,45 +29,46 @@ func New(name, desc string) *sApp {
|
||||
}
|
||||
app.AddCmd(NewAboutCmd(app))
|
||||
app.AddCmd(NewAirCmd(app))
|
||||
app.AddCmd(NewGenCmd(app))
|
||||
app.AddCmd(NewListCmd(app))
|
||||
app.AddCmd(NewHelpCmd(app))
|
||||
return app
|
||||
}
|
||||
|
||||
func (s *sApp) GetCmds() map[string]ICommand {
|
||||
func (s *ConsoleApp) GetCmds() map[string]ICommand {
|
||||
return s.cmds
|
||||
}
|
||||
|
||||
func (s *sApp) GetName() string {
|
||||
func (s *ConsoleApp) GetName() string {
|
||||
return s.name
|
||||
}
|
||||
|
||||
func (s *sApp) GetDesc() string {
|
||||
func (s *ConsoleApp) GetDesc() string {
|
||||
return s.desc
|
||||
}
|
||||
|
||||
func (s *sApp) GetVersion() string {
|
||||
func (s *ConsoleApp) GetVersion() string {
|
||||
return s.version
|
||||
}
|
||||
|
||||
func (s *sApp) AddCmd(cmd ICommand) {
|
||||
func (s *ConsoleApp) AddCmd(cmd ICommand) {
|
||||
s.cmds[cmd.GetName()] = cmd
|
||||
}
|
||||
|
||||
func (s *sApp) HasCmd(cmd string) bool {
|
||||
func (s *ConsoleApp) HasCmd(cmd string) bool {
|
||||
_, ok := s.cmds[cmd]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s *sApp) SetExtraAbout(about ActionHandler) {
|
||||
func (s *ConsoleApp) SetExtraAbout(about ActionHandler) {
|
||||
s.about = about
|
||||
}
|
||||
|
||||
func (s *sApp) GetExtraAbout() ActionHandler {
|
||||
func (s *ConsoleApp) GetExtraAbout() ActionHandler {
|
||||
return s.about
|
||||
}
|
||||
|
||||
func (s *sApp) Run(args []string) {
|
||||
func (s *ConsoleApp) Run(args []string) {
|
||||
cmd := "list"
|
||||
if len(args) == 1 {
|
||||
args = []string{cmd}
|
||||
|
Loading…
Reference in New Issue
Block a user