dubeejw commented on a change in pull request #2326: (Review) Alphabetize
URL: 
https://github.com/apache/incubator-openwhisk/pull/2326#discussion_r124102412
 
 

 ##########
 File path: tools/cli/go-whisk-cli/commands/util.go
 ##########
 @@ -242,27 +242,70 @@ func getEscapedJSON(value string) (string) {
 func isValidJSON(value string) (bool) {
     var jsonInterface interface{}
     err := json.Unmarshal([]byte(value), &jsonInterface)
+
     return err == nil
 }
 
 var boldString = color.New(color.Bold).SprintFunc()
 
+type SortCmds []whisk.Sortable
+// Uses Go builtin sort to sort commands based on their compare methods
+// Param: Takes in a array of Sortable interfaces which contains a specific 
command
+func (s SortCmds) Len() int { return len(s) }
+func (s SortCmds) Less(i,j int) bool { return s[i].Compare(s[j]) }
+func (s SortCmds) Swap(i,j int) { s[i], s[j] = s[j], s[i] }
+
+// Prints the parameters/list for wsk xxxx list
+// Identifies type and then copies array into an array of interfaces(Sortable) 
to be sorted and printed
+// Param: Takes in an interace which contains an array of a command(Ex: 
[]Action)
 func printList(collection interface{}) {
-    switch collection := collection.(type) {
+    var commandToSort []whisk.Sortable
+    switch collection := collection.(type){
     case []whisk.Action:
-        printActionList(collection)
+        for i := range collection {
+            commandToSort = append(commandToSort, collection[i])
+        }
+        sort.Sort(SortCmds(commandToSort))
+        printCommandsList(commandToSort, "actions")
     case []whisk.Trigger:
-        printTriggerList(collection)
+      for i := range collection {
+          commandToSort = append(commandToSort, collection[i])
+      }
+      sort.Sort(SortCmds(commandToSort))
+      printCommandsList(commandToSort, "triggers")
     case []whisk.Package:
-        printPackageList(collection)
+      for i := range collection {
+          commandToSort = append(commandToSort, collection[i])
+      }
+      sort.Sort(SortCmds(commandToSort))
+      printCommandsList(commandToSort, "packages")
     case []whisk.Rule:
-        printRuleList(collection)
+      for i := range collection {
+        commandToSort = append(commandToSort, collection[i])
+      }
+      sort.Sort(SortCmds(commandToSort))
+      printCommandsList(commandToSort, "rules")
     case []whisk.Namespace:
-        printNamespaceList(collection)
+      for i := range collection {
+        commandToSort = append(commandToSort, collection[i])
+      }
+      sort.Sort(SortCmds(commandToSort))
+      printCommandsList(commandToSort, "namespaces")
     case []whisk.Activation:
         printActivationList(collection)
-    case []whisk.Api:
-        printApiList(collection)
+    case []whisk.ApiFilteredList:
+      for i:= range collection {
 
 Review comment:
   Space after `i`.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to