mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
优化代码
This commit is contained in:
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user