@@ -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+
400449func 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" ,
0 commit comments