From 2bdf9e23b9c869d2e24c41d489fe9d6259b5b034 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Tue, 14 Nov 2023 14:40:47 +0200 Subject: [PATCH] Print project list as multiple rows in `whoami` subcommand (#1648) This enables us to print several projects in an easy way in case it would be enabled for a specific user. --- cmd/cli/app/auth/auth_whoami.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/cmd/cli/app/auth/auth_whoami.go b/cmd/cli/app/auth/auth_whoami.go index 73f04652e0..547db6195e 100644 --- a/cmd/cli/app/auth/auth_whoami.go +++ b/cmd/cli/app/auth/auth_whoami.go @@ -18,7 +18,6 @@ package auth import ( "fmt" "os" - "strings" "github.com/charmbracelet/bubbles/table" "github.com/spf13/cobra" @@ -63,19 +62,10 @@ func init() { } func renderUserInfoWhoami(cmd *cobra.Command, conn *grpc.ClientConn, user *pb.GetUserResponse) { - projects := []string{} - for _, project := range user.Projects { - projects = append(projects, fmt.Sprintf("%s:%s", project.GetName(), project.GetProjectId())) - } - subjectKey := "Subject" createdKey := "Created At" updatedKey := "Updated At" minderSrvKey := "Minder Server" - projectKey := "Projects" - if len(projects) > 1 { - projectKey += "s" - } rows := []table.Row{ { subjectKey, user.GetUser().GetIdentitySubject(), @@ -86,13 +76,19 @@ func renderUserInfoWhoami(cmd *cobra.Command, conn *grpc.ClientConn, user *pb.Ge { updatedKey, user.GetUser().GetUpdatedAt().AsTime().String(), }, - { - projectKey, strings.Join(projects, ", "), - }, { minderSrvKey, conn.Target(), }, } + projectKey := "Project" + for idx, project := range user.Projects { + if len(user.Projects) > 1 { + projectKey = fmt.Sprintf("Project #%d", idx+1) + } + projectVal := fmt.Sprintf("%s / %s", project.GetName(), project.GetProjectId()) + rows = append(rows, table.Row{projectKey, projectVal}) + } + renderUserToTable(cmd, rows) }