github.com/crowdsecurity/crowdsec@v1.6.1/cmd/crowdsec-cli/notifications_table.go (about)

     1  package main
     2  
     3  import (
     4  	"io"
     5  	"sort"
     6  	"strings"
     7  
     8  	"github.com/aquasecurity/table"
     9  
    10  	"github.com/crowdsecurity/crowdsec/pkg/emoji"
    11  )
    12  
    13  func notificationListTable(out io.Writer, ncfgs map[string]NotificationsCfg) {
    14  	t := newLightTable(out)
    15  	t.SetHeaders("Active", "Name", "Type", "Profile name")
    16  	t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)
    17  	t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)
    18  
    19  	keys := make([]string, 0, len(ncfgs))
    20  	for k := range ncfgs {
    21  		keys = append(keys, k)
    22  	}
    23  
    24  	sort.Slice(keys, func(i, j int) bool {
    25  		return len(ncfgs[keys[i]].Profiles) > len(ncfgs[keys[j]].Profiles)
    26  	})
    27  
    28  	for _, k := range keys {
    29  		b := ncfgs[k]
    30  		profilesList := []string{}
    31  
    32  		for _, p := range b.Profiles {
    33  			profilesList = append(profilesList, p.Name)
    34  		}
    35  
    36  		active := emoji.CheckMark
    37  		if len(profilesList) == 0 {
    38  			active = emoji.Prohibited
    39  		}
    40  
    41  		t.AddRow(active, b.Config.Name, b.Config.Type, strings.Join(profilesList, ", "))
    42  	}
    43  
    44  	t.Render()
    45  }