mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
替换日志库为slog
This commit is contained in:
@@ -11,8 +11,9 @@ type CommandFunctionCB func(args interface{}) error
|
||||
var commandList []*command
|
||||
var programName string
|
||||
const(
|
||||
boolType valueType = iota
|
||||
stringType valueType = iota
|
||||
boolType valueType = 0
|
||||
stringType valueType = 1
|
||||
intType valueType = 2
|
||||
)
|
||||
|
||||
type command struct{
|
||||
@@ -20,6 +21,7 @@ type command struct{
|
||||
name string
|
||||
bValue bool
|
||||
strValue string
|
||||
intValue int
|
||||
usage string
|
||||
fn CommandFunctionCB
|
||||
}
|
||||
@@ -29,6 +31,8 @@ func (cmd *command) execute() error{
|
||||
return cmd.fn(cmd.bValue)
|
||||
}else if cmd.valType == stringType {
|
||||
return cmd.fn(cmd.strValue)
|
||||
}else if cmd.valType == intType {
|
||||
return cmd.fn(cmd.intValue)
|
||||
}else{
|
||||
return fmt.Errorf("Unknow command type.")
|
||||
}
|
||||
@@ -72,6 +76,16 @@ func RegisterCommandBool(cmdName string, defaultValue bool, usage string,fn Comm
|
||||
commandList = append(commandList,&cmd)
|
||||
}
|
||||
|
||||
func RegisterCommandInt(cmdName string, defaultValue int, usage string,fn CommandFunctionCB){
|
||||
var cmd command
|
||||
cmd.valType = intType
|
||||
cmd.name = cmdName
|
||||
cmd.fn = fn
|
||||
cmd.usage = usage
|
||||
flag.IntVar(&cmd.intValue, cmdName, defaultValue, usage)
|
||||
commandList = append(commandList,&cmd)
|
||||
}
|
||||
|
||||
func RegisterCommandString(cmdName string, defaultValue string, usage string,fn CommandFunctionCB){
|
||||
var cmd command
|
||||
cmd.valType = stringType
|
||||
|
||||
Reference in New Issue
Block a user