Skip to content

Commit

Permalink
Print project list as multiple rows in whoami subcommand (#1648)
Browse files Browse the repository at this point in the history
This enables us to print several projects in an easy way in case it would
be enabled for a specific user.
  • Loading branch information
JAORMX authored Nov 14, 2023
1 parent d3b412e commit 2bdf9e2
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions cmd/cli/app/auth/auth_whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package auth
import (
"fmt"
"os"
"strings"

"github.com/charmbracelet/bubbles/table"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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(),
Expand All @@ -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)
}

0 comments on commit 2bdf9e2

Please sign in to comment.