From 867039b5060c080baa947b4f1a985a72c4535d7f Mon Sep 17 00:00:00 2001 From: "ning.yougang" Date: Tue, 24 May 2022 14:41:23 +0800 Subject: [PATCH 1/3] Support array result --- commands/action.go | 12 ++++++------ commands/util.go | 16 ++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/commands/action.go b/commands/action.go index 7d4f5fd61..9bd465cbe 100644 --- a/commands/action.go +++ b/commands/action.go @@ -199,7 +199,7 @@ func invokeAction( qualifiedName QualifiedName, parameters interface{}, blocking bool, - result bool) (map[string]interface{}, error) { + result bool) (interface{}, error) { // TODO remove all global modifiers Client.Namespace = qualifiedName.GetNamespace() res, _, err := Client.Actions.Invoke( @@ -214,7 +214,7 @@ func printInvocationResponse( qualifiedName QualifiedName, blocking bool, header bool, - result map[string]interface{}, + result interface{}, err error) error { if err == nil { printInvocationMsg(qualifiedName, blocking, header, result, color.Output) @@ -232,13 +232,13 @@ func printInvocationResponse( func printFailedBlockingInvocationResponse( qualifiedName QualifiedName, header bool, - result map[string]interface{}, + result interface{}, err error) error { if isBlockingTimeout(err) { printBlockingTimeoutMsg( qualifiedName.GetNamespace(), qualifiedName.GetEntityName(), - getValueFromJSONResponse(ACTIVATION_ID, result)) + getValueFromResponse(ACTIVATION_ID, result)) return err } else if isApplicationError(err) { printInvocationMsg( @@ -1169,7 +1169,7 @@ func printInvocationMsg( qualifiedName QualifiedName, blocking bool, header bool, - response map[string]interface{}, + response interface{}, outputStream io.Writer) { if header { fmt.Fprintf( @@ -1180,7 +1180,7 @@ func printInvocationMsg( "ok": color.GreenString("ok:"), "namespace": boldString(qualifiedName.GetNamespace()), "name": boldString(qualifiedName.GetEntityName()), - "id": boldString(getValueFromJSONResponse(ACTIVATION_ID, response)), + "id": boldString(getValueFromResponse(ACTIVATION_ID, response)), })) } diff --git a/commands/util.go b/commands/util.go index 3fd930ef2..d6fd2e211 100644 --- a/commands/util.go +++ b/commands/util.go @@ -604,16 +604,20 @@ func getChildValueStrings(keyValueArr whisk.KeyValueArr, key string, childKey st return res } -func getValueFromJSONResponse(field string, response map[string]interface{}) interface{} { +func getValueFromResponse(field string, response interface{}) interface{} { var res interface{} - for key, value := range response { - if key == field { - res = value - break + if result, ok := response.(map[string]interface{}); ok { + for key, value := range result { + if key == field { + res = value + break + } } } - + if result, ok := response.([]interface{}); ok { + res = result + } return res } From 443499c1cd848b63d424b275a02fc09403676f86 Mon Sep 17 00:00:00 2001 From: "ning.yougang" Date: Thu, 18 Aug 2022 17:12:15 +0800 Subject: [PATCH 2/3] Fix review comment If return array, make the result return empty string --- commands/util.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/util.go b/commands/util.go index d6fd2e211..72eb3ede5 100644 --- a/commands/util.go +++ b/commands/util.go @@ -617,6 +617,8 @@ func getValueFromResponse(field string, response interface{}) interface{} { } if result, ok := response.([]interface{}); ok { res = result + } else { + res = "" } return res } From ae92c3376d5314e02ee77c3d52c8b88aaacae88d Mon Sep 17 00:00:00 2001 From: "ning.yougang" Date: Sun, 21 Aug 2022 11:28:11 +0800 Subject: [PATCH 3/3] Fix does not return activationId --- commands/util.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/commands/util.go b/commands/util.go index 72eb3ede5..66f6f1e77 100644 --- a/commands/util.go +++ b/commands/util.go @@ -605,22 +605,18 @@ func getChildValueStrings(keyValueArr whisk.KeyValueArr, key string, childKey st } func getValueFromResponse(field string, response interface{}) interface{} { - var res interface{} - if result, ok := response.(map[string]interface{}); ok { for key, value := range result { if key == field { - res = value - break + return value } } } if result, ok := response.([]interface{}); ok { - res = result + return result } else { - res = "" + return "" } - return res } func logoText() string {