Skip to content

Commit

Permalink
edited tableString to use maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Devaansh-Kumar committed Jul 8, 2024
1 parent dfc4cfc commit e3dbb65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (pr *PrintRunner) PrintGatewayAPIObjects(cmd *cobra.Command, _ []string) er
return err
}

if tableString != nil {
fmt.Println(tableString)
for _, table := range tableString {
fmt.Println(table)
}

pr.outputResult(gatewayResources)
Expand Down
2 changes: 1 addition & 1 deletion pkg/i2gw/ingress2gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
)

func ToGatewayAPIResources(ctx context.Context, namespace string, inputFile string, providers []string, providerSpecificFlags map[string]map[string]string) ([]GatewayResources, *strings.Builder, error) {
func ToGatewayAPIResources(ctx context.Context, namespace string, inputFile string, providers []string, providerSpecificFlags map[string]map[string]string) ([]GatewayResources, map[string]*strings.Builder, error) {
var clusterClient client.Client

if inputFile == "" {
Expand Down
13 changes: 9 additions & 4 deletions pkg/i2gw/notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ func (na *NotificationAggregator) DispatchNotification(notification Notification

// CreateNotificationTables takes all generated notifications and returns a string.Builder
// that displays the notifications in a tabular format based on provider
func (na *NotificationAggregator) CreateNotificationTables() *strings.Builder {
tableString := &strings.Builder{}
func (na *NotificationAggregator) CreateNotificationTables() map[string]*strings.Builder {
tableString := map[string]*strings.Builder{}

for provider, msgs := range na.Notifications {
t := tablewriter.NewWriter(tableString)
providerTable := strings.Builder{}

t := tablewriter.NewWriter(&providerTable)
t.SetHeader([]string{"Message Type", "Notification", "Calling Object"})
t.SetColWidth(200)
t.SetRowLine(true)
Expand All @@ -73,9 +76,11 @@ func (na *NotificationAggregator) CreateNotificationTables() *strings.Builder {
t.Append(row)
}

tableString.WriteString(fmt.Sprintf("Notifications from %v\n", provider))
providerTable.WriteString(fmt.Sprintf("Notifications from %v:\n", strings.ToUpper(provider)))
tableString[provider] = &providerTable
t.Render()
}

return tableString
}

Expand Down

0 comments on commit e3dbb65

Please sign in to comment.