From 3094faf55e643bffabf1603e25a97906febd7593 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea Date: Thu, 12 Jan 2023 20:10:53 +0100 Subject: [PATCH] Add user role list renderer --- internal/cli/users_roles.go | 2 +- internal/display/roles.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/cli/users_roles.go b/internal/cli/users_roles.go index df24b852b..6d7d1bcb0 100644 --- a/internal/cli/users_roles.go +++ b/internal/cli/users_roles.go @@ -53,7 +53,7 @@ func showUserRolesCmd(cli *cli) *cobra.Command { return fmt.Errorf("failed to find roles for user with ID %s: %w", inputs.ID, err) } - cli.renderer.RoleList(userRoleList.Roles) + cli.renderer.UserRoleList(userRoleList.Roles) return nil }, diff --git a/internal/display/roles.go b/internal/display/roles.go index c2415a9fb..330627e0b 100644 --- a/internal/display/roles.go +++ b/internal/display/roles.go @@ -58,6 +58,24 @@ func (r *Renderer) RoleList(roles []*management.Role) { r.Results(res) } +func (r *Renderer) UserRoleList(roles []*management.Role) { + resource := "roles assigned to user" + r.Heading(fmt.Sprintf("%s (%d)", resource, len(roles))) + + if len(roles) == 0 { + r.EmptyState(resource) + r.Infof("Use 'auth0 users roles assign' to add one") + return + } + + var res []View + for _, role := range roles { + res = append(res, makeRoleView(role)) + } + + r.Results(res) +} + func (r *Renderer) RoleShow(role *management.Role) { r.Heading("role") r.Result(makeRoleView(role))