diff --git a/cli/client/call_fn.go b/cli/client/call_fn.go index b058eefd1..925874da2 100644 --- a/cli/client/call_fn.go +++ b/cli/client/call_fn.go @@ -33,7 +33,7 @@ type callID struct { Error apiErr `json:"error"` } -func CallFN(u string, content io.Reader, output io.Writer, method string, env []string) error { +func CallFN(u string, content io.Reader, output io.Writer, method string, env []string, displayCallID bool) error { if method == "" { if content == nil { method = "GET" @@ -59,7 +59,9 @@ func CallFN(u string, content io.Reader, output io.Writer, method string, env [] } // for sync calls if call_id, found := resp.Header[FN_CALL_ID]; found { - fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", call_id[0])) + if displayCallID { + fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", call_id[0])) + } io.Copy(output, resp.Body) } else { // for async calls and error discovering @@ -71,7 +73,9 @@ func CallFN(u string, content io.Reader, output io.Writer, method string, env [] // - error in body // that's why we need to check values of attributes if c.CallID != "" { - fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", c.CallID)) + if displayCallID { + fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", c.CallID)) + } } else { fmt.Fprint(output, fmt.Sprintf("Error: %v\n", c.Error.Message)) } diff --git a/cli/routes.go b/cli/routes.go index 9a713fb5e..8670246bf 100644 --- a/cli/routes.go +++ b/cli/routes.go @@ -60,6 +60,13 @@ var updateRouteFlags = append(routeFlags, Usage: "defines whether skip func file or not", }) +var callFnFlags = append(runflags(), + cli.BoolFlag{ + Name: "display-call-id", + Usage: "whether display call ID or not for sync calls", + }, +) + func routes() cli.Command { r := routesCmd{client: client.APIClient()} @@ -73,7 +80,7 @@ func routes() cli.Command { Usage: "call a route", ArgsUsage: " [image]", Action: r.call, - Flags: runflags(), + Flags: callFnFlags, }, { Name: "list", @@ -143,7 +150,7 @@ func call() cli.Command { Name: "call", Usage: "call a remote function", ArgsUsage: " ", - Flags: runflags(), + Flags: callFnFlags, Action: r.call, } } @@ -200,7 +207,7 @@ func (a *routesCmd) call(c *cli.Context) error { u.Path = path.Join(u.Path, "r", appName, route) content := stdin() - return client.CallFN(u.String(), content, os.Stdout, c.String("method"), c.StringSlice("e")) + return client.CallFN(u.String(), content, os.Stdout, c.String("method"), c.StringSlice("e"), c.BoolT("display-call-id")) } func routeWithFlags(c *cli.Context, rt *fnmodels.Route) { diff --git a/cli/testfn.go b/cli/testfn.go index 81105706b..e83bb0f6c 100644 --- a/cli/testfn.go +++ b/cli/testfn.go @@ -211,7 +211,7 @@ func runremotetest(target string, in *inputMap, expectedOut *outputMap, expected os.Setenv(k, v) restrictedEnv = append(restrictedEnv, k) } - if err := client.CallFN(target, stdin, &stdout, "", restrictedEnv); err != nil { + if err := client.CallFN(target, stdin, &stdout, "", restrictedEnv, false); err != nil { return fmt.Errorf("%v\nstdout:%s\n", err, stdout.String()) }