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

 ##########
 File path: tools/cli/go-whisk-cli/commands/util.go
 ##########
 @@ -242,27 +242,78 @@ 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] }
+
+func toPrintable(sortable []whisk.Sortable) []whisk.Printable{
+    sortedPrintable := make([]whisk.Printable, len(sortable), len(sortable))
+    for i := range sortable {
+        sortedPrintable[i] = sortable[i].(whisk.Printable)
+    }
+    return sortedPrintable
+}
+
+// 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){
 
 Review comment:
   Move common code outside of the switch statement so that it's not 
duplicated.  Just use the switch for the type dependent stuff - like setting 
the commandName value used as the parameter to printCommandsList.
 
----------------------------------------------------------------
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