You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2017/08/17 17:17:42 UTC

[incubator-openwhisk-cli] 01/10: Summary updates for actions without annotated descriptions: (#2490)

This is an automated email from the ASF dual-hosted git repository.

csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git

commit ab4c0a81d6978dee05abba3e651bd45c0b40b422
Author: Brandon Lee Underwood <Br...@ibm.com>
AuthorDate: Thu Aug 10 21:36:31 2017 -0400

    Summary updates for actions without annotated descriptions: (#2490)
    
    * Added '(parameters: none defined)' when getting entity with no parameters
    * Function builds generic description from parameters
    * Added testing for Actions, Triggers, and Packages
    * Finalized actions now denoted by "*"
    * Update help file to reflect action summary changes
    * Parameters marked as bound and final
    * Bound parameters prefixed by "*", finalized parameters denoted by "**"
    * Testing for trigger/action/package get summary cases, including bound and finalized for actions
    * Updated docs
---
 commands/action.go               |  2 +-
 commands/package.go              |  2 +-
 commands/trigger.go              |  2 +-
 commands/util.go                 | 91 ++++++++++++++++++++++++++++++++++++----
 wski18n/resources/en_US.all.json | 12 +++---
 5 files changed, 93 insertions(+), 16 deletions(-)

diff --git a/commands/action.go b/commands/action.go
index 28f09b3..40eaeff 100644
--- a/commands/action.go
+++ b/commands/action.go
@@ -937,7 +937,7 @@ func init() {
     actionInvokeCmd.Flags().BoolVarP(&Flags.common.blocking, "blocking", "b", false, wski18n.T("blocking invoke"))
     actionInvokeCmd.Flags().BoolVarP(&Flags.action.result, "result", "r", false, wski18n.T("blocking invoke; show only activation result (unless there is a failure)"))
 
-    actionGetCmd.Flags().BoolVarP(&Flags.common.summary, "summary", "s", false, wski18n.T("summarize action details"))
+    actionGetCmd.Flags().BoolVarP(&Flags.common.summary, "summary", "s", false, wski18n.T("summarize action details; parameters with prefix \"*\" are bound, \"**\" are bound and finalized"))
     actionGetCmd.Flags().BoolVarP(&Flags.action.url, "url", "r", false, wski18n.T("get action url"))
 
     actionListCmd.Flags().IntVarP(&Flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result"))
diff --git a/commands/package.go b/commands/package.go
index e0a5694..aed7c19 100644
--- a/commands/package.go
+++ b/commands/package.go
@@ -514,7 +514,7 @@ func init() {
   packageUpdateCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))
   packageUpdateCmd.Flags().StringVar(&Flags.common.shared, "shared", "", wski18n.T("package visibility `SCOPE`; yes = shared, no = private"))
 
-  packageGetCmd.Flags().BoolVarP(&Flags.common.summary, "summary", "s", false, wski18n.T("summarize package details"))
+  packageGetCmd.Flags().BoolVarP(&Flags.common.summary, "summary", "s", false, wski18n.T("summarize package details; parameters with prefix \"*\" are bound"))
 
   packageBindCmd.Flags().StringSliceVarP(&Flags.common.annotation, "annotation", "a", []string{}, wski18n.T("annotation values in `KEY VALUE` format"))
   packageBindCmd.Flags().StringVarP(&Flags.common.annotFile, "annotation-file", "A", "", wski18n.T("`FILE` containing annotation values in JSON format"))
diff --git a/commands/trigger.go b/commands/trigger.go
index a2bae83..40524b6 100644
--- a/commands/trigger.go
+++ b/commands/trigger.go
@@ -503,7 +503,7 @@ func init() {
     triggerUpdateCmd.Flags().StringSliceVarP(&Flags.common.param, "param", "p", []string{}, wski18n.T("parameter values in `KEY VALUE` format"))
     triggerUpdateCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))
 
-    triggerGetCmd.Flags().BoolVarP(&Flags.trigger.summary, "summary", "s", false, wski18n.T("summarize trigger details"))
+    triggerGetCmd.Flags().BoolVarP(&Flags.trigger.summary, "summary", "s", false, wski18n.T("summarize trigger details; parameters with prefix \"*\" are bound"))
 
     triggerFireCmd.Flags().StringSliceVarP(&Flags.common.param, "param", "p", []string{}, wski18n.T("parameter values in `KEY VALUE` format"))
     triggerFireCmd.Flags().StringVarP(&Flags.common.paramFile, "param-file", "P", "", wski18n.T("`FILE` containing parameter values in JSON format"))
diff --git a/commands/util.go b/commands/util.go
index c02e15f..faeb728 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -387,14 +387,15 @@ func printArrayContents(arrStr []string) {
 func printPackageSummary(pkg *whisk.Package) {
     printEntitySummary(fmt.Sprintf("%7s", "package"), getFullName(pkg.Namespace, pkg.Name, ""),
         getValueString(pkg.Annotations, "description"),
-        strings.Join(getChildValueStrings(pkg.Annotations, "parameters", "name"), ", "))
+        strings.Join(getParamUnion(pkg.Annotations, pkg.Parameters, "name"), ", "))
 
 
     if pkg.Actions != nil {
         for _, action := range pkg.Actions {
+            paramUnion := getParamUnion(action.Annotations, action.Parameters, "name")
             printEntitySummary(fmt.Sprintf("%7s", "action"), getFullName(pkg.Namespace, pkg.Name, action.Name),
                 getValueString(action.Annotations, "description"),
-                strings.Join(getChildValueStrings(action.Annotations, "parameters", "name"), ", "))
+                strings.Join(paramUnion, ", "))
         }
     }
 
@@ -402,23 +403,24 @@ func printPackageSummary(pkg *whisk.Package) {
         for _, feed := range pkg.Feeds {
             printEntitySummary(fmt.Sprintf("%7s", "feed  "), getFullName(pkg.Namespace, pkg.Name, feed.Name),
                 getValueString(feed.Annotations, "description"),
-                strings.Join(getChildValueStrings(feed.Annotations, "parameters", "name"), ", "))
+                strings.Join(getParamUnion(feed.Annotations, feed.Parameters, "name"), ", "))
         }
     }
 }
 
 func printActionSummary(action *whisk.Action) {
+    paramUnion := getParamUnion(action.Annotations, action.Parameters, "name")
     printEntitySummary(fmt.Sprintf("%6s", "action"),
         getFullName(action.Namespace, "", action.Name),
         getValueString(action.Annotations, "description"),
-        strings.Join(getChildValueStrings(action.Annotations, "parameters", "name"), ", "))
+        strings.Join(paramUnion, ", "))
 }
 
 func printTriggerSummary(trigger *whisk.Trigger) {
     printEntitySummary(fmt.Sprintf("%7s", "trigger"),
         getFullName(trigger.Namespace, "", trigger.Name),
         getValueString(trigger.Annotations, "description"),
-        strings.Join(getChildValueStrings(trigger.Annotations, "parameters", "name"), ", "))
+        strings.Join(getParamUnion(trigger.Annotations, trigger.Parameters, "name"), ", "))
 }
 
 func printRuleSummary(rule *whisk.Rule) {
@@ -428,15 +430,74 @@ func printRuleSummary(rule *whisk.Rule) {
 }
 
 func printEntitySummary(entityType string, fullName string, description string, params string) {
+    emptyParams := "none defined"
+    if len(params) <= 0 {
+        params = emptyParams
+    }
     if len(description) > 0 {
         fmt.Fprintf(color.Output, "%s %s: %s\n", boldString(entityType), fullName, description)
+    } else if params != emptyParams {
+        descriptionFromParams := buildParamDescription(params)
+        fmt.Fprintf(color.Output, "%s %s: %s\n", boldString(entityType), fullName, descriptionFromParams)
     } else {
         fmt.Fprintf(color.Output, "%s %s\n", boldString(entityType), fullName)
     }
+    fmt.Fprintf(color.Output, "   (%s: %s)\n", boldString(wski18n.T("parameters")), params)
+}
+
+//  getParamUnion(keyValArrAnnots, keyValArrParams, key) returns the union
+//      of parameters listed under annotations (keyValArrAnnots, using key) and
+//      bound parameters (keyValArrParams). Bound parameters will be denoted with
+//      a prefixed "*", and finalized bound parameters (can't be changed by
+//      user) will be denoted by a prefixed "**".
+func getParamUnion(keyValArrAnnots whisk.KeyValueArr, keyValArrParams whisk.KeyValueArr, key string) []string {
+    var res []string
+    tag := "*"
+    if getValueBool(keyValArrAnnots, "final") {
+        tag = "**"
+    }
+    boundParams := getKeys(keyValArrParams)
+    annotatedParams := getChildValueStrings(keyValArrAnnots, "parameters", key)
+    res = append(boundParams, annotatedParams...)       // Create union of boundParams and annotatedParams with duplication
+    for i := 0; i < len(res); i++ {
+        for j := i + 1; j < len(res); j++ {
+            if res[i] == res[j] {
+                res = append(res[:j], res[j+1:]...)     // Remove duplicate entry
+            }
+        }
+    }
+    sort.Strings(res)
+    res = tagBoundParams(boundParams, res, tag)
+    return res
+}
 
-    if len(params) > 0 {
-        fmt.Fprintf(color.Output, "   (%s: %s)\n", boldString(wski18n.T("parameters")), params)
+//  tagBoundParams(boundParams, paramUnion, tag) returns the list paramUnion with
+//      all strings listed under boundParams set with a prefix tag.
+func tagBoundParams(boundParams []string, paramUnion []string, tag string) []string {
+    res := paramUnion
+    for i := 0; i < len(boundParams); i++ {
+        for j := 0; j < len(res); j++ {
+            if boundParams[i] == res[j] {
+                res[j] = fmt.Sprintf("%s%s", tag, res[j])
+            }
+        }
     }
+    return res
+}
+
+//  buildParamDescription(params) returns a default entity description for
+//      `$ wsk [ENTITY] get [ENTITY_NAME] --summary` when parameters are defined,
+//      but the entity description under annotations is not.
+func buildParamDescription(params string) string {
+    preamble := "Returns a result based on parameter"
+    params = strings.Replace(params, "*", "", -1)
+    temp := strings.Split(params, ",")
+    if len(temp) > 1 {
+        lastParam := temp[len(temp) - 1]
+        newParams := strings.Replace(params, fmt.Sprintf(",%s", lastParam), fmt.Sprintf(" and%s", lastParam), 1)
+        return fmt.Sprintf("%ss %s", preamble, newParams)
+    }
+    return fmt.Sprintf("%s %s", preamble, params)
 }
 
 func getFullName(namespace string, packageName string, entityName string) (string) {
@@ -504,6 +565,22 @@ func getValueString(keyValueArr whisk.KeyValueArr, key string) (string) {
     return res
 }
 
+func getValueBool(keyValueArr whisk.KeyValueArr, key string) (bool) {
+    var value interface{}
+    var res bool
+
+    value = keyValueArr.GetValue(key)
+    castedValue, canCast := value.(bool)
+
+    if (canCast) {
+        res = castedValue
+    }
+
+    whisk.Debug(whisk.DbgInfo, "Got bool value '%v' for key '%s'\n", res, key)
+
+    return res
+}
+
 func getChildValues(keyValueArr whisk.KeyValueArr, key string, childKey string) ([]interface{}) {
     var value interface{}
     var res []interface{}
diff --git a/wski18n/resources/en_US.all.json b/wski18n/resources/en_US.all.json
index 2140b9e..78acda0 100644
--- a/wski18n/resources/en_US.all.json
+++ b/wski18n/resources/en_US.all.json
@@ -221,8 +221,8 @@
     "translation": "package visibility `SCOPE`; yes = shared, no = private"
   },
   {
-    "id": "summarize package details",
-    "translation": "summarize package details"
+    "id": "summarize package details; parameters with prefix \"*\" are bound",
+    "translation": "summarize package details; parameters with prefix \"*\" are bound"
   },
   {
     "id": "include publicly shared entities in the result",
@@ -700,8 +700,8 @@
     "translation": "trigger feed `ACTION_NAME`"
   },
   {
-    "id": "summarize trigger details",
-    "translation": "summarize trigger details"
+    "id": "summarize trigger details; parameters with prefix \"*\" are bound",
+    "translation": "summarize trigger details; parameters with prefix \"*\" are bound"
   },
   {
     "id": "parameter values in `KEY VALUE` format",
@@ -952,8 +952,8 @@
     "translation": "only return `LIMIT` number of actions from the collection"
   },
   {
-    "id": "summarize action details",
-    "translation": "summarize action details"
+    "id": "summarize action details; parameters with prefix \"*\" are bound, \"**\" are bound and finalized",
+    "translation": "summarize action details; parameters with prefix \"*\" are bound, \"**\" are bound and finalized"
   },
   {
     "id": "work with activations",

-- 
To stop receiving notification emails like this one, please contact
"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>.