You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2019/04/10 14:56:38 UTC

[incubator-openwhisk-cli] branch master updated: Add dynamic column sizing to wsk activation list command (#427)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 096792a  Add dynamic column sizing to wsk activation list command (#427)
096792a is described below

commit 096792a9763fe33f8eb34421daaef582768aea83
Author: Lars Andersson <la...@users.noreply.github.com>
AuthorDate: Wed Apr 10 16:56:33 2019 +0200

    Add dynamic column sizing to wsk activation list command (#427)
    
    * Updated build.gradle to latest commit of incubator-openwhisk-client-go
    * Updated vendor.json
---
 build.gradle           |  2 +-
 commands/activation.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-
 commands/util.go       |  4 +++-
 vendor/vendor.json     |  6 +++---
 4 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/build.gradle b/build.gradle
index d3b0047..24f9ec1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -57,7 +57,7 @@ dependencies {
         build(['name':'golang.org/x/sys/unix', 'version':'7f918dd405547ecb864d14a8ecbbfe205b5f930f', 'transitive':false])
         build(['name':'gopkg.in/yaml.v2', 'version':'eb3733d160e74a9c7e442f435eb3bea458e1d19f', 'transitive':false])
         build(['name':'github.com/ghodss/yaml', 'version':'0ca9ea5df5451ffdf184b4428c902747c2c11cd7', 'transitive':false])
-        build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'4286a8212a74c40d8950ee76681a67e12c9bf1a0','transitive':false])
+        build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'47ad3426a4e3632fd17d859303f4074ae7b959ff','transitive':false])
         build(['name':'github.com/apache/incubator-openwhisk-wskdeploy','version':'7d79fd74ca1045658196e5004f8820b67570734c','transitive':false])
         // END - Imported from Godeps
         test name:'github.com/stretchr/testify', version:'b91bfb9ebec76498946beb6af7c0230c7cc7ba6c', transitive:false //, tag: 'v1.2.0'
diff --git a/commands/activation.go b/commands/activation.go
index 6dbde79..023eeb0 100644
--- a/commands/activation.go
+++ b/commands/activation.go
@@ -22,6 +22,7 @@ import (
 	"fmt"
 	"os"
 	"os/signal"
+	"strconv"
 	"syscall"
 	"time"
 
@@ -53,6 +54,7 @@ var activationListCmd = &cobra.Command{
 	RunE: func(cmd *cobra.Command, args []string) error {
 		var err error
 		var qualifiedName = new(QualifiedName)
+		var orderedFilteredRow []whisk.ActivationFilteredRow
 
 		if whiskErr := CheckArgs(args, 0, 1, "Activation list",
 			wski18n.T("An optional namespace is the only valid argument.")); whiskErr != nil {
@@ -93,7 +95,18 @@ var activationListCmd = &cobra.Command{
 		if options.Docs == true {
 			printFullActivationList(activations)
 		} else {
-			printList(activations, false) // Default sorting for Activations are by creation time, hence sortByName is always false
+			maxKindSize := max(len("Kind"), getLargestKindSize(activations))
+			maxStatusSize := max(len("Status"), getLargestStatusSize(activations))
+
+			// Header string should show "Datetime", "Activation ID", "Kind", "Start", "Duration", "Status", "Entity", with Kind and Status being
+			// dynamically sized. The last column Entity will be sized correctly when printed, so no need to calculate size here
+			headerFmt := "%-19s %-32s %-" + strconv.Itoa(maxKindSize) + "s %-6s%-10s %-" + strconv.Itoa(maxStatusSize) + "s %-6s\n"
+			rowFmt := "%d-%02d-%02d %02d:%02d:%02d %-32s %-" + strconv.Itoa(maxKindSize) + "s %-5s %-10v %-" + strconv.Itoa(maxStatusSize) + "s %-"
+
+			for i := 0; i < len(activations); i++ {
+				orderedFilteredRow = append(orderedFilteredRow, whisk.ActivationFilteredRow{Row: activations[i], HeaderFmt: headerFmt, RowFmt: rowFmt})
+			}
+			printList(orderedFilteredRow, false) // Default sorting for Activations are by creation time, hence sortByName is always false
 		}
 
 		return nil
@@ -397,6 +410,42 @@ var activationPollCmd = &cobra.Command{
 	},
 }
 
+// Find the size needed for the Kind column when listing activations
+func getLargestKindSize(activations []whisk.Activation) int {
+	var maxLen = 0
+	var curLen int
+	var kind interface{}
+
+	for i := 0; i < len(activations); i++ {
+		kind = activations[i].Annotations.GetValue("kind")
+		if kind == nil {
+			kind = "unknown"
+		}
+		curLen = len(kind.(string))
+		if curLen > maxLen {
+			maxLen = curLen
+		}
+	}
+	return maxLen
+}
+
+// Find the size needed for the Status column when listing activations
+func getLargestStatusSize(activations []whisk.Activation) int {
+	// The first array in the StatusCodes variable is "success"
+	var maxLen = len(whisk.StatusCodes[0])
+	var curLen int
+
+	for i := 0; i < len(activations); i++ {
+		if activations[i].StatusCode > 0 && activations[i].StatusCode < len(whisk.StatusCodes) {
+			curLen = len(whisk.StatusCodes[activations[i].StatusCode])
+			if curLen > maxLen {
+				maxLen = curLen
+			}
+		}
+	}
+	return maxLen
+}
+
 func init() {
 	activationListCmd.Flags().IntVarP(&Flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of activations from the result"))
 	activationListCmd.Flags().IntVarP(&Flags.common.limit, "limit", "l", DEFAULT_ACTIVATION_LIMIT, wski18n.T("only return `LIMIT` number of activations from the collection with a maximum LIMIT of {{.max}} activations",
diff --git a/commands/util.go b/commands/util.go
index 3fbafbe..757ecff 100644
--- a/commands/util.go
+++ b/commands/util.go
@@ -212,7 +212,7 @@ func printList(collection interface{}, sortByName bool) {
 		for i := range collection {
 			commandToSort = append(commandToSort, collection[i])
 		}
-	case []whisk.Activation:
+	case []whisk.ActivationFilteredRow:
 		for i := range collection {
 			commandToSort = append(commandToSort, collection[i])
 		}
@@ -266,6 +266,8 @@ func makeDefaultHeader(collection interface{}) string {
 		defaultHeader = fmt.Sprintf("%-30s %7s %20s  %s", "Action", "Verb", "API Name", "URL")
 	} else if defaultHeader == "apifilteredlists" {
 		defaultHeader = ""
+	} else if defaultHeader == "activationfilteredrows" {
+		defaultHeader = ""
 	}
 	return defaultHeader
 }
diff --git a/vendor/vendor.json b/vendor/vendor.json
index aa9b068..8b90bf2 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -3,10 +3,10 @@
 	"ignore": "test",
 	"package": [
 		{
-			"checksumSHA1": "6D6U+hfBxkxhDZWSHTrn8uhGod8=",
+			"checksumSHA1": "W0Cr3GbXN1qhrbg6BVwt2VH9qSQ=",
 			"path": "github.com/apache/incubator-openwhisk-client-go/whisk",
-			"revision": "4286a8212a74c40d8950ee76681a67e12c9bf1a0",
-			"revisionTime": "2019-03-04T14:44:55Z"
+			"revision": "47ad3426a4e3632fd17d859303f4074ae7b959ff",
+			"revisionTime": "2019-04-04T18:35:19Z"
 		},
 		{
 			"checksumSHA1": "4NY5lFykxXaoN+JNMxo179L79sU=",