no more reflection

This commit is contained in:
Radu Ioan Fericean
2012-10-01 13:07:07 +03:00
parent 7dd14f9038
commit 9349c27f76
6 changed files with 43 additions and 50 deletions

View File

@@ -3,7 +3,6 @@ package console
import (
"fmt"
"path/filepath"
"reflect"
)
// Console Command interface
@@ -16,22 +15,6 @@ type Commander interface {
defaults() error // set defaults wherever necessary
}
// Set command fields based on indexes defined in default()
func CmdRpcPrmsFromArgs(rpcPrms interface{}, args []string, idxArgsToRpcPrms map[int]string) {
for idx := range args {
fldName, hasIdx := idxArgsToRpcPrms[idx]
if !hasIdx {
continue
}
// field defined to be set by os.Args index
if fld := reflect.ValueOf(rpcPrms).Elem().FieldByName(fldName); fld.Kind() == reflect.String {
fld.SetString(args[idx])
} else if fld.Kind() == reflect.Int {
fld.SetInt(1) // Placeholder for future usage of data types other than strings
}
}
}
// Process args and return right command Value or error
func GetCommandValue(args []string) (Commander, error) {
if len(args) < 2 {