X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=extras%2Fhs-test%2Fmain.go;h=9de0d314cb2bab8f13f75d82792a9cc701e8026a;hb=1a9dc75fe8099fdde9b1dd248a8fca35b001f9fc;hp=f54b6c4d91053d71967f9623489e70cc268156a6;hpb=b79d09bbfa93f0f752f7249ad27a08eae0863a6b;p=vpp.git diff --git a/extras/hs-test/main.go b/extras/hs-test/main.go index f54b6c4d910..9de0d314cb2 100755 --- a/extras/hs-test/main.go +++ b/extras/hs-test/main.go @@ -7,15 +7,10 @@ import ( "os" "os/exec" "os/signal" - - "git.fd.io/govpp.git/api" + "reflect" ) -type CfgTable map[string]func([]string) *ActionResult - -var cfgTable CfgTable - -type ConfFn func(context.Context, api.Connection) error +var actions Actions func newVppContext() (context.Context, context.CancelFunc) { ctx, cancel := signal.NotifyContext( @@ -116,15 +111,18 @@ func OkResult() *ActionResult { return NewActionResult(nil) } -func reg(key string, fn func([]string) *ActionResult) { - cfgTable[key] = fn -} - func processArgs() *ActionResult { - fn := cfgTable[os.Args[1]] - if fn == nil { - return NewActionResult(fmt.Errorf("internal: no config found for %s", os.Args[1])) + nArgs := len(os.Args) - 1 // skip program name + if nArgs < 1 { + return NewActionResult(fmt.Errorf("internal: no action specified!")) + } + action := os.Args[1] + methodValue := reflect.ValueOf(&actions).MethodByName(action) + if !methodValue.IsValid() { + return NewActionResult(fmt.Errorf("internal unknown action %s!", action)) } + methodIface := methodValue.Interface() + fn := methodIface.(func([]string) *ActionResult) return fn(os.Args) } @@ -144,8 +142,6 @@ func main() { os.Exit(0) } - RegisterActions() - var err error res := processArgs() err = writeSyncFile(res)