From 8cd876ff45713d89e2afc9f39e9c007b7d6ab0d3 Mon Sep 17 00:00:00 2001 From: Sreedeep CV Date: Sat, 15 Jun 2024 19:56:56 +0530 Subject: [PATCH] Removing reduntant code --- controller/controller.cli.go | 37 ++++------------------------------- controller/controller.go | 6 +----- controller/controller.wasm.go | 23 +++------------------- 3 files changed, 8 insertions(+), 58 deletions(-) diff --git a/controller/controller.cli.go b/controller/controller.cli.go index b93aa6dc..15ee8113 100644 --- a/controller/controller.cli.go +++ b/controller/controller.cli.go @@ -101,48 +101,19 @@ func ExecuteRequestorBlockHelper(block *gabs.Container, args ...interface{}) htt } } } - - if vm != nil { - preprocess.ProcessVarsInBlock(block, vm) - } else { - preprocess.ProcessVarsInBlock(block, nil) - } - - if opts != nil { - cmd, stdinBody = cmdgen.ConstructCommand(block, opts) - } else { - cmd, stdinBody = cmdgen.ConstructCommand(block, opts) - } - + preprocess.ProcessVarsInBlock(block, vm) + cmd, stdinBody = cmdgen.ConstructCommand(block, opts) var resp httpie.ExResponse var e1 error - if dir != "" { - resp, e1 = cmdexec.ExecCommand(cmd, stdinBody, dir) - } else { - resp, e1 = cmdexec.ExecCommand(cmd, stdinBody, "") - } - + resp, e1 = cmdexec.ExecCommand(cmd, stdinBody, dir) headers := resp.Headers var headersString string for key, value := range headers { headersString += fmt.Sprintf("%s: %s\n", key, value) } - - // TODO: Getting html results for widget - // targetHeader := "text/html" - // isTextHTMLPresent := strings.Contains(headersString, targetHeader) - - // if isTextHTMLPresent { - // return resp - // } else { - // fmt.Printf("'%s' is not present in the headers.\n", targetHeader) if e1 == nil { chainCode := cmdexec.GenerateChainCode(resp.Body) - if vm != nil { - cmdexec.RunVMCode(chainCode, vm) - } else { - cmdexec.RunVMCode(chainCode, vm) - } + cmdexec.RunVMCode(chainCode, vm) } else { fmt.Printf("Error from ExecCommand", e1) os.Exit(1) diff --git a/controller/controller.go b/controller/controller.go index 55097d82..1e13f6a9 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -38,11 +38,7 @@ func extractArgs(args []interface{}) (*goja.Runtime, *lama2cmd.Opts, string) { func processLama2FileBlock(block *gabs.Container, vm *goja.Runtime, o *lama2cmd.Opts, dir string) httpie.ExResponse { var resp httpie.ExResponse - if vm != nil && o != nil && dir != "" { - resp = ExecuteRequestorBlock(block, vm, o, dir) - } else { - resp = ExecuteRequestorBlock(block, vm, o, dir) - } + resp = ExecuteRequestorBlock(block, vm, o, dir) return resp } diff --git a/controller/controller.wasm.go b/controller/controller.wasm.go index 6e655777..63289543 100644 --- a/controller/controller.wasm.go +++ b/controller/controller.wasm.go @@ -45,7 +45,6 @@ func ProcessWasmInput(data string) (httpie.ExResponse, *lama2cmd.Opts) { // Print the parsedAPI value fmt.Printf("Parsed API: %+v\n", parsedAPI) - fmt.Println(parsedAPI) return HandleParsedFile(parsedAPI) } @@ -66,28 +65,13 @@ func ExecuteRequestorBlockHelper(block *gabs.Container, args ...interface{}) htt } } } - - if vm != nil { - preprocess.ProcessVarsInBlock(block, vm) - } else { - preprocess.ProcessVarsInBlock(block, vm) - } + preprocess.ProcessVarsInBlock(block, vm) var cmd []string var stdinBody string - if opts != nil { - cmd, stdinBody = cmdgen.ConstructCommand(block, opts) - } else { - cmd, stdinBody = cmdgen.ConstructCommand(block, opts) - } - + cmd, stdinBody = cmdgen.ConstructCommand(block, opts) var resp httpie.ExResponse var e1 error - if dir != "" { - resp, e1 = cmdexec.ExecCommand(cmd, stdinBody, dir) - } else { - resp, e1 = cmdexec.ExecCommand(cmd, stdinBody, dir) - } - + resp, e1 = cmdexec.ExecCommand(cmd, stdinBody, dir) headers := resp.Headers var headersString string for key, value := range headers { @@ -108,7 +92,6 @@ func ExecuteRequestorBlockHelper(block *gabs.Container, args ...interface{}) htt cmdexec.RunVMCode(chainCode, vm) } else { ExecuteJsCodeWasm(chainCode) - // js.Global().Call("eval", chainCode) } } else { fmt.Println("Error from ExecCommand", e1)