@@ -52,13 +52,25 @@ func NewDetailsCommand(sl *metadata.SoftlayerCommand) (cmd *DetailsCommand) {
5252 return thisCmd
5353}
5454
55+ type UserInformation struct {
56+ User datatypes.User_Customer
57+ Hardware []datatypes.Hardware
58+ Virtual []datatypes.Virtual_Guest
59+ Events []datatypes.Event_Log
60+ Permissions []datatypes.User_Customer_CustomerPermission_Permission
61+ Logins []datatypes.User_Customer_Access_Authentication
62+ DedicatedHosts []datatypes.Virtual_DedicatedHost
63+ }
64+
5565func (cmd * DetailsCommand ) Run (args []string ) error {
5666 userId := args [0 ]
5767 id , err := strconv .Atoi (userId )
5868 if err != nil {
5969 return errors .NewInvalidUsageError (T ("User ID should be a number." ))
6070 }
6171
72+ outputFormat := cmd .GetOutputFlag ()
73+ userInfo := UserInformation {}
6274 keys := cmd .Keys
6375 permissions := cmd .Permissions
6476 hardware := cmd .Hardware
@@ -68,11 +80,14 @@ func (cmd *DetailsCommand) Run(args []string) error {
6880
6981 object_mask := "userStatus[name],parent[id,username],apiAuthenticationKeys[authenticationKey]"
7082 user , err := cmd .UserManager .GetUser (id , object_mask )
83+ userInfo .User = user
7184 if err != nil {
7285 return errors .NewAPIError (T ("Failed to show user detail.\n " ), err .Error (), 2 )
7386 }
7487
75- baseUserPrint (user , keys , cmd .UI )
88+ if outputFormat != "JSON" {
89+ baseUserPrint (user , keys , cmd .UI )
90+ }
7691
7792 if permissions {
7893 perms , err := cmd .UserManager .GetUserPermissions (id )
@@ -84,7 +99,10 @@ func (cmd *DetailsCommand) Run(args []string) error {
8499 table .Add (utils .FormatStringPointer (perm .KeyName ), utils .FormatStringPointer (perm .Name ))
85100 }
86101 table .Add ("" , "" )
87- table .Print ()
102+ if outputFormat != "JSON" {
103+ table .Print ()
104+ }
105+ userInfo .Permissions = perms
88106 }
89107
90108 if hardware {
@@ -105,7 +123,6 @@ func (cmd *DetailsCommand) Run(args []string) error {
105123 table .Add (hostId , hostFqdn , hostCpu , hostMem , hostDisk , hostCreated )
106124 }
107125 table .Add ("" , "" )
108- table .Print ()
109126
110127 tableAccess := cmd .UI .Table ([]string {T ("ID" ), T ("Hostname" ), T ("Primary Public IP" ), T ("Primary Private IP" ), T ("Created" )})
111128 for _ , host := range access .Hardware {
@@ -117,7 +134,12 @@ func (cmd *DetailsCommand) Run(args []string) error {
117134 tableAccess .Add (hostId , hostFqdn , hostPrimary , hostPrivate , hostCreated )
118135 }
119136 tableAccess .Add ("" , "" )
120- tableAccess .Print ()
137+ if outputFormat != "JSON" {
138+ table .Print ()
139+ tableAccess .Print ()
140+ }
141+ userInfo .Hardware = access .Hardware
142+ userInfo .DedicatedHosts = access .DedicatedHosts
121143 }
122144
123145 if virtual {
@@ -137,7 +159,10 @@ func (cmd *DetailsCommand) Run(args []string) error {
137159 tableAccess .Add (hostId , hostFqdn , hostPrimary , hostPrivate , hostCreated )
138160 }
139161 tableAccess .Add ("" , "" )
140- tableAccess .Print ()
162+ if outputFormat != "JSON" {
163+ tableAccess .Print ()
164+ }
165+ userInfo .Virtual = access .VirtualGuests
141166 }
142167
143168 if logins {
@@ -156,7 +181,11 @@ func (cmd *DetailsCommand) Run(args []string) error {
156181 table .Add (loginData , loginIp , loginSucc )
157182 }
158183 table .Add ("" , "" )
159- table .Print ()
184+ if outputFormat != "JSON" {
185+ table .Print ()
186+ }
187+ userInfo .Logins = loginLog
188+
160189 }
161190
162191 if events {
@@ -176,9 +205,16 @@ func (cmd *DetailsCommand) Run(args []string) error {
176205 table .Add (eventData , eventName , eventIp , eventLabel , eventUsername )
177206 }
178207 table .Add ("" , "" )
179- table .Print ()
208+ if outputFormat != "JSON" {
209+ table .Print ()
210+ }
211+ userInfo .Events = events
180212 }
181213
214+ if outputFormat == "JSON" {
215+ err := utils .PrintPrettyJSON (cmd .UI , userInfo )
216+ return err
217+ }
182218 return nil
183219
184220}
0 commit comments