@@ -14,8 +14,6 @@ import (
1414const (
1515 statusRegistered = "Registered"
1616 statusNotRegistered = "Not Registered"
17- deviceTypeDevice = "device"
18- deviceTypeEmulator = "emulator"
1917)
2018
2119type DeviceConnectListOptions struct {
@@ -24,15 +22,17 @@ type DeviceConnectListOptions struct {
2422
2523// DeviceDTO is the API response structure for devices
2624type DeviceDTO struct {
27- ID string `json:"id"`
28- TransportID string `json:"transportId"`
29- Serialno string `json:"serialno"`
30- AndroidID string `json:"androidId"`
31- Model string `json:"model"`
32- Manufacturer string `json:"manufacturer"`
33- ConnectionType string `json:"connectionType"`
34- IsRegistered bool `json:"isRegistered"`
35- RegId string `json:"regId"`
25+ ID string `json:"id"`
26+ TransportID string `json:"transportId"`
27+ Serialno string `json:"serialno"`
28+ AndroidID string `json:"androidId"`
29+ Platform string `json:"platform"` // mobile, desktop
30+ OS string `json:"os"` // android, linux, windows, macos
31+ DeviceType string `json:"deviceType"` // physical, emulator, vm
32+ IsRegistered bool `json:"isRegistered"`
33+ RegId string `json:"regId"`
34+ IsLocal bool `json:"isLocal"` // true if this is the local desktop device
35+ Metadata map [string ]interface {} `json:"metadata"` // Device-specific metadata
3636}
3737
3838func NewDeviceConnectListCommand () * cobra.Command {
@@ -96,45 +96,8 @@ func ExecuteDeviceConnectList(cmd *cobra.Command, opts *DeviceConnectListOptions
9696}
9797
9898func outputDevicesJSONFromAPI (devices []DeviceDTO ) error {
99- // Create a simplified JSON output for compatibility
100- type SimpleDeviceInfo struct {
101- RegId string `json:"reg_id"`
102- DeviceID string `json:"device_id"`
103- Name string `json:"name"`
104- Type string `json:"type"`
105- ConnectionStatus string `json:"connection_status"`
106- }
107-
108- var simpleDevices []SimpleDeviceInfo
109- for _ , device := range devices {
110- deviceID := device .ID
111- name := device .Model
112- serialNo := device .Serialno
113- regId := device .RegId
114- isRegistered := device .IsRegistered
115-
116- status := statusNotRegistered
117- if isRegistered {
118- // Color "Registered" in green for better visibility
119- status = "\u001b [32m" + statusRegistered + "\u001b [0m"
120- }
121-
122- deviceType := deviceTypeDevice
123- // Check if it's an emulator based on serial number
124- if strings .Contains (strings .ToUpper (serialNo ), "EMULATOR" ) {
125- deviceType = deviceTypeEmulator
126- }
127-
128- simpleDevices = append (simpleDevices , SimpleDeviceInfo {
129- RegId : regId ,
130- DeviceID : deviceID ,
131- Name : name ,
132- Type : deviceType ,
133- ConnectionStatus : status ,
134- })
135- }
136-
137- jsonBytes , err := json .MarshalIndent (simpleDevices , "" , " " )
99+ // Output full DeviceDTO with all fields
100+ jsonBytes , err := json .MarshalIndent (devices , "" , " " )
138101 if err != nil {
139102 return fmt .Errorf ("failed to marshal devices to JSON: %v" , err )
140103 }
@@ -144,7 +107,7 @@ func outputDevicesJSONFromAPI(devices []DeviceDTO) error {
144107
145108func outputDevicesTextFromAPI (devices []DeviceDTO ) error {
146109 if len (devices ) == 0 {
147- fmt .Println ("No Android devices found." )
110+ fmt .Println ("No devices found." )
148111 return nil
149112 }
150113
@@ -153,14 +116,13 @@ func outputDevicesTextFromAPI(devices []DeviceDTO) error {
153116 serial string
154117 deviceID string
155118 serialOrTransport string
156- name string
119+ os string
157120 deviceType string
158121 status string
159122 }
160123 rows := make ([]row , 0 , len (devices ))
161124 for _ , device := range devices {
162125 deviceID := device .ID
163- name := device .Model
164126 serialNo := device .Serialno
165127 transportID := device .TransportID
166128 isRegistered := device .IsRegistered
@@ -171,20 +133,62 @@ func outputDevicesTextFromAPI(devices []DeviceDTO) error {
171133 status = "\x1b [32m" + statusRegistered + "\x1b [0m"
172134 }
173135
174- deviceType := deviceTypeDevice
175- // Check if it's an emulator based on serial number
176- if strings .Contains (strings .ToUpper (serialNo ), "EMULATOR" ) {
177- deviceType = deviceTypeEmulator
136+ // Get OS and DeviceType from device
137+ os := device .OS
138+ if os == "" {
139+ os = "-"
140+ }
141+
142+ // Get osVersion from metadata and combine with OS
143+ osVersion := ""
144+ if device .Metadata != nil {
145+ if ov , ok := device .Metadata ["osVersion" ].(string ); ok && ov != "" {
146+ osVersion = ov
147+ }
148+ }
149+
150+ // Format OS display: capitalize first letter and handle macOS
151+ osDisplay := os
152+ if os != "-" && os != "" {
153+ osLower := strings .ToLower (os )
154+ switch osLower {
155+ case "android" :
156+ osDisplay = "Android"
157+ case "macos" :
158+ osDisplay = "MacOS"
159+ case "linux" :
160+ osDisplay = "Linux"
161+ case "windows" :
162+ osDisplay = "Windows"
163+ default :
164+ // Capitalize first letter
165+ if len (os ) > 0 {
166+ osDisplay = strings .ToUpper (os [:1 ]) + strings .ToLower (os [1 :])
167+ }
168+ }
169+
170+ // Append version if available
171+ if osVersion != "" {
172+ osDisplay = fmt .Sprintf ("%s %s" , osDisplay , osVersion )
173+ }
174+ }
175+
176+ deviceType := device .DeviceType
177+ if deviceType == "" {
178+ deviceType = "-"
178179 }
179180
180- // Display "-" for empty fields
181- if name == "" {
182- name = "-"
181+ // Get connectionType from metadata for Android devices
182+ connectionType := ""
183+ if device .Metadata != nil {
184+ if ct , ok := device .Metadata ["connectionType" ].(string ); ok {
185+ connectionType = ct
186+ }
183187 }
184188
185189 // Second column: for USB show Serial No; otherwise show Transport ID (full value)
186190 serialOrTransport := transportID
187- if strings .EqualFold (device . ConnectionType , "usb" ) && strings .TrimSpace (serialNo ) != "" {
191+ if strings .EqualFold (connectionType , "usb" ) && strings .TrimSpace (serialNo ) != "" {
188192 serialOrTransport = serialNo
189193 }
190194
@@ -198,7 +202,7 @@ func outputDevicesTextFromAPI(devices []DeviceDTO) error {
198202 serial : device .Serialno ,
199203 deviceID : uniqueDeviceID ,
200204 serialOrTransport : serialOrTransport ,
201- name : name ,
205+ os : osDisplay ,
202206 deviceType : deviceType ,
203207 status : status ,
204208 })
@@ -221,8 +225,8 @@ func outputDevicesTextFromAPI(devices []DeviceDTO) error {
221225 tableData [i ] = map [string ]interface {}{
222226 "device_id" : r .deviceID ,
223227 "serial_or_transport" : r .serialOrTransport ,
224- "name " : r . name ,
225- "type" : r .deviceType ,
228+ "os " : r . os ,
229+ "device_type" : r .deviceType ,
226230 "status" : r .status ,
227231 }
228232 }
@@ -231,8 +235,8 @@ func outputDevicesTextFromAPI(devices []DeviceDTO) error {
231235 columns := []util.TableColumn {
232236 {Header : "DEVICE ID" , Key : "device_id" },
233237 {Header : "SERIAL NO/TRANSPORT ID" , Key : "serial_or_transport" },
234- {Header : "MODEL " , Key : "name " },
235- {Header : "TYPE" , Key : "type " },
238+ {Header : "OS " , Key : "os " },
239+ {Header : "DEVICE TYPE" , Key : "device_type " },
236240 {Header : "STATUS" , Key : "status" },
237241 }
238242
0 commit comments