@@ -17,14 +17,10 @@ import (
1717)
1818
1919func newUserDescribeCommand (s * state.State ) * cobra.Command {
20- return base.Cmd {
21- BaseCobraCommand : func () * cobra.Command {
22- return & cobra.Command {
23- Use : "describe <user-id-or-email>" ,
24- Short : "Describe a user and their assigned roles" ,
25- Args : util .ExactArgs (1 , "a user ID or email" ),
26- }
27- },
20+ return base.DescribeCmd [* iamv1.User ]{
21+ Use : "describe <user-id-or-email>" ,
22+ Short : "Describe a user and their assigned roles" ,
23+ Args : util .ExactArgs (1 , "a user ID or email" ),
2824 Long : `Describe a user and their assigned roles.
2925
3026Accepts either a user ID (UUID) or an email address. Displays the user's
@@ -37,23 +33,27 @@ qcloud iam user describe user@example.com
3733
3834# Output as JSON
3935qcloud iam user describe user@example.com --json` ,
40- Run : func (s * state.State , cmd * cobra.Command , args []string ) error {
41- ctx := cmd .Context ()
42- client , err := s .Client (ctx )
36+ Fetch : func (s * state.State , cmd * cobra.Command , args []string ) (* iamv1.User , error ) {
37+ client , err := s .Client (cmd .Context ())
4338 if err != nil {
44- return err
39+ return nil , err
4540 }
4641 accountID , err := s .AccountID ()
42+ if err != nil {
43+ return nil , err
44+ }
45+ return resolveUser (cmd , client , accountID , args [0 ])
46+ },
47+ PrintText : func (cmd * cobra.Command , w io.Writer , user * iamv1.User ) error {
48+ ctx := cmd .Context ()
49+ client , err := s .Client (ctx )
4750 if err != nil {
4851 return err
4952 }
50-
51- user , err := resolveUser (cmd , client , accountID , args [0 ])
53+ accountID , err := s .AccountID ()
5254 if err != nil {
5355 return err
5456 }
55-
56- // Fetch the user's roles.
5757 rolesResp , err := client .IAM ().ListUserRoles (ctx , & iamv1.ListUserRolesRequest {
5858 AccountId : accountID ,
5959 UserId : user .GetId (),
@@ -62,18 +62,7 @@ qcloud iam user describe user@example.com --json`,
6262 return fmt .Errorf ("failed to list user roles: %w" , err )
6363 }
6464 roles := rolesResp .GetRoles ()
65-
66- permissions := effectivePermissions (roles )
67-
68- if s .Config .JSONOutput () {
69- return output .PrintJSON (cmd .OutOrStdout (), struct {
70- User * iamv1.User `json:"user"`
71- Roles []* iamv1.Role `json:"roles"`
72- }{User : user , Roles : roles })
73- }
74-
75- w := cmd .OutOrStdout ()
76- return printUserWithRoles (w , user , roles , permissions )
65+ return printUserWithRoles (w , user , roles , effectivePermissions (roles ))
7766 },
7867 }.CobraCommand (s )
7968}
0 commit comments