Skip to content

Commit 096792a

Browse files
laranderssonrabbah
authored andcommitted
Add dynamic column sizing to wsk activation list command (#427)
* Updated build.gradle to latest commit of incubator-openwhisk-client-go * Updated vendor.json
1 parent 46bddcf commit 096792a

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ dependencies {
5757
build(['name':'golang.org/x/sys/unix', 'version':'7f918dd405547ecb864d14a8ecbbfe205b5f930f', 'transitive':false])
5858
build(['name':'gopkg.in/yaml.v2', 'version':'eb3733d160e74a9c7e442f435eb3bea458e1d19f', 'transitive':false])
5959
build(['name':'github.com/ghodss/yaml', 'version':'0ca9ea5df5451ffdf184b4428c902747c2c11cd7', 'transitive':false])
60-
build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'4286a8212a74c40d8950ee76681a67e12c9bf1a0','transitive':false])
60+
build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'47ad3426a4e3632fd17d859303f4074ae7b959ff','transitive':false])
6161
build(['name':'github.com/apache/incubator-openwhisk-wskdeploy','version':'7d79fd74ca1045658196e5004f8820b67570734c','transitive':false])
6262
// END - Imported from Godeps
6363
test name:'github.com/stretchr/testify', version:'b91bfb9ebec76498946beb6af7c0230c7cc7ba6c', transitive:false //, tag: 'v1.2.0'

commands/activation.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"fmt"
2323
"os"
2424
"os/signal"
25+
"strconv"
2526
"syscall"
2627
"time"
2728

@@ -53,6 +54,7 @@ var activationListCmd = &cobra.Command{
5354
RunE: func(cmd *cobra.Command, args []string) error {
5455
var err error
5556
var qualifiedName = new(QualifiedName)
57+
var orderedFilteredRow []whisk.ActivationFilteredRow
5658

5759
if whiskErr := CheckArgs(args, 0, 1, "Activation list",
5860
wski18n.T("An optional namespace is the only valid argument.")); whiskErr != nil {
@@ -93,7 +95,18 @@ var activationListCmd = &cobra.Command{
9395
if options.Docs == true {
9496
printFullActivationList(activations)
9597
} else {
96-
printList(activations, false) // Default sorting for Activations are by creation time, hence sortByName is always false
98+
maxKindSize := max(len("Kind"), getLargestKindSize(activations))
99+
maxStatusSize := max(len("Status"), getLargestStatusSize(activations))
100+
101+
// Header string should show "Datetime", "Activation ID", "Kind", "Start", "Duration", "Status", "Entity", with Kind and Status being
102+
// dynamically sized. The last column Entity will be sized correctly when printed, so no need to calculate size here
103+
headerFmt := "%-19s %-32s %-" + strconv.Itoa(maxKindSize) + "s %-6s%-10s %-" + strconv.Itoa(maxStatusSize) + "s %-6s\n"
104+
rowFmt := "%d-%02d-%02d %02d:%02d:%02d %-32s %-" + strconv.Itoa(maxKindSize) + "s %-5s %-10v %-" + strconv.Itoa(maxStatusSize) + "s %-"
105+
106+
for i := 0; i < len(activations); i++ {
107+
orderedFilteredRow = append(orderedFilteredRow, whisk.ActivationFilteredRow{Row: activations[i], HeaderFmt: headerFmt, RowFmt: rowFmt})
108+
}
109+
printList(orderedFilteredRow, false) // Default sorting for Activations are by creation time, hence sortByName is always false
97110
}
98111

99112
return nil
@@ -397,6 +410,42 @@ var activationPollCmd = &cobra.Command{
397410
},
398411
}
399412

413+
// Find the size needed for the Kind column when listing activations
414+
func getLargestKindSize(activations []whisk.Activation) int {
415+
var maxLen = 0
416+
var curLen int
417+
var kind interface{}
418+
419+
for i := 0; i < len(activations); i++ {
420+
kind = activations[i].Annotations.GetValue("kind")
421+
if kind == nil {
422+
kind = "unknown"
423+
}
424+
curLen = len(kind.(string))
425+
if curLen > maxLen {
426+
maxLen = curLen
427+
}
428+
}
429+
return maxLen
430+
}
431+
432+
// Find the size needed for the Status column when listing activations
433+
func getLargestStatusSize(activations []whisk.Activation) int {
434+
// The first array in the StatusCodes variable is "success"
435+
var maxLen = len(whisk.StatusCodes[0])
436+
var curLen int
437+
438+
for i := 0; i < len(activations); i++ {
439+
if activations[i].StatusCode > 0 && activations[i].StatusCode < len(whisk.StatusCodes) {
440+
curLen = len(whisk.StatusCodes[activations[i].StatusCode])
441+
if curLen > maxLen {
442+
maxLen = curLen
443+
}
444+
}
445+
}
446+
return maxLen
447+
}
448+
400449
func init() {
401450
activationListCmd.Flags().IntVarP(&Flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of activations from the result"))
402451
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",

commands/util.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func printList(collection interface{}, sortByName bool) {
212212
for i := range collection {
213213
commandToSort = append(commandToSort, collection[i])
214214
}
215-
case []whisk.Activation:
215+
case []whisk.ActivationFilteredRow:
216216
for i := range collection {
217217
commandToSort = append(commandToSort, collection[i])
218218
}
@@ -266,6 +266,8 @@ func makeDefaultHeader(collection interface{}) string {
266266
defaultHeader = fmt.Sprintf("%-30s %7s %20s %s", "Action", "Verb", "API Name", "URL")
267267
} else if defaultHeader == "apifilteredlists" {
268268
defaultHeader = ""
269+
} else if defaultHeader == "activationfilteredrows" {
270+
defaultHeader = ""
269271
}
270272
return defaultHeader
271273
}

vendor/vendor.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"ignore": "test",
44
"package": [
55
{
6-
"checksumSHA1": "6D6U+hfBxkxhDZWSHTrn8uhGod8=",
6+
"checksumSHA1": "W0Cr3GbXN1qhrbg6BVwt2VH9qSQ=",
77
"path": "github.com/apache/incubator-openwhisk-client-go/whisk",
8-
"revision": "4286a8212a74c40d8950ee76681a67e12c9bf1a0",
9-
"revisionTime": "2019-03-04T14:44:55Z"
8+
"revision": "47ad3426a4e3632fd17d859303f4074ae7b959ff",
9+
"revisionTime": "2019-04-04T18:35:19Z"
1010
},
1111
{
1212
"checksumSHA1": "4NY5lFykxXaoN+JNMxo179L79sU=",

0 commit comments

Comments
 (0)