Apply opposite logic call ID CLI flag

use --ignore-call-id flag to mute call ID
 call id now goes to STDERR
This commit is contained in:
Denis Makogon
2017-08-03 18:00:34 +03:00
parent e4bade376a
commit ab8134cbbb
2 changed files with 8 additions and 8 deletions

View File

@@ -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, displayCallID bool) error {
func CallFN(u string, content io.Reader, output io.Writer, method string, env []string, ignoreCallID bool) error {
if method == "" {
if content == nil {
method = "GET"
@@ -59,8 +59,8 @@ 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 {
if displayCallID {
fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", call_id[0]))
if !ignoreCallID {
fmt.Fprint(os.Stderr, fmt.Sprintf("Call ID: %v\n", call_id[0]))
}
io.Copy(output, resp.Body)
} else {
@@ -73,8 +73,8 @@ 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 != "" {
if displayCallID {
fmt.Fprint(output, fmt.Sprintf("Call ID: %v\n", c.CallID))
if !ignoreCallID {
fmt.Fprint(os.Stderr, fmt.Sprintf("Call ID: %v\n", c.CallID))
}
} else {
fmt.Fprint(output, fmt.Sprintf("Error: %v\n", c.Error.Message))

View File

@@ -62,8 +62,8 @@ var updateRouteFlags = append(routeFlags,
var callFnFlags = append(runflags(),
cli.BoolFlag{
Name: "display-call-id",
Usage: "whether display call ID or not for sync calls",
Name: "ignore-call-id",
Usage: "whether display call ID or not",
},
)
@@ -207,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"), c.BoolT("display-call-id"))
return client.CallFN(u.String(), content, os.Stdout, c.String("method"), c.StringSlice("e"), c.Bool("ignore-call-id"))
}
func routeWithFlags(c *cli.Context, rt *fnmodels.Route) {