优化代码

This commit is contained in:
boyce
2020-10-29 20:45:33 +08:00
parent be792337fb
commit 3025eaebd5
7 changed files with 189 additions and 206 deletions

View File

@@ -9,6 +9,7 @@ import (
type valueType int
type CommandFunctionCB func(args interface{}) error
var commandList []*command
var programName string
const(
boolType valueType = iota
stringType valueType = iota
@@ -29,15 +30,12 @@ func (cmd *command) execute() error{
}else if cmd.valType == stringType {
return cmd.fn(cmd.strValue)
}else{
return fmt.Errorf("unknow command type!")
return fmt.Errorf("Unknow command type.")
}
return nil
}
var programName string
func Run(args []string) error {
flag.Parse()
programName = args[0]
@@ -57,7 +55,11 @@ func Run(args []string) error {
}
}
return startCmd.execute()
if startCmd != nil {
return startCmd.execute()
}
return fmt.Errorf("Command input parameter error,try `%s -help` for help",args[0])
}
func RegisterCommandBool(cmdName string, defaultValue bool, usage string,fn CommandFunctionCB){