Skip to content

Commit

Permalink
Merge pull request #64 from sam80180/main
Browse files Browse the repository at this point in the history
fix: collect errors and print at the end
  • Loading branch information
ZhouYixun authored Aug 16, 2023
2 parents b424fa2 + fe891cc commit 9ffd12c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
28 changes: 19 additions & 9 deletions cmd/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ package cmd
import (
"encoding/json"
"fmt"
"os"

giDevice "github.com/SonicCloudOrg/sonic-gidevice"
"github.com/SonicCloudOrg/sonic-ios-bridge/src/entity"
"github.com/SonicCloudOrg/sonic-ios-bridge/src/util"
"github.com/spf13/cobra"
"os"
)

var devicesCmd = &cobra.Command{
Expand All @@ -37,11 +38,12 @@ var devicesCmd = &cobra.Command{
return util.NewErrorPrint(util.ErrConnect, "usbMux", err)
}
list, err1 := usbMuxClient.Devices()
remoteList, err2 := util.ReadRemote()
remoteList, errRemoto := util.ReadRemote()

if err1 != nil {
return util.NewErrorPrint(util.ErrSendCommand, "listDevices", err1)
}
todosErrores := []error{}
if len(list) != 0 || len(remoteList) != 0 {
if len(list) == 0 {
list = []giDevice.Device{}
Expand All @@ -53,25 +55,27 @@ var devicesCmd = &cobra.Command{
if isDetail {
detail, err2 := entity.GetDetail(d)
if err2 != nil {
return err2
todosErrores = append(todosErrores, err2)
} else {
device.DeviceDetail = *detail
}
device.DeviceDetail = *detail
}
json.Unmarshal(deviceByte, device)
device.Status = device.GetStatus()
device.RemoteAddr = "localhost"
deviceList.DeviceList = append(deviceList.DeviceList, *device)
}
if err2 == nil {
if errRemoto == nil {
for k, dev := range remoteList {
deviceByte, _ := json.Marshal(dev.Properties())
device := &entity.Device{}
if isDetail {
detail, err2 := entity.GetDetail(dev)
if err2 != nil {
return err2
todosErrores = append(todosErrores, err2)
} else {
device.DeviceDetail = *detail
}
device.DeviceDetail = *detail
}
json.Unmarshal(deviceByte, device)
device.Status = device.GetStatus()
Expand All @@ -93,9 +97,10 @@ var devicesCmd = &cobra.Command{
if isDetail {
detail, err2 := entity.GetDetail(d)
if err2 != nil {
return err2
todosErrores = append(todosErrores, err2)
} else {
device.DeviceDetail = *detail
}
device.DeviceDetail = *detail
}
json.Unmarshal(deviceByte, device)
device.Status = device.GetStatus()
Expand All @@ -114,6 +119,11 @@ var devicesCmd = &cobra.Command{
os.Exit(0)
}
}
if len(todosErrores) > 0 {
for _, e := range todosErrores {
fmt.Fprintf(os.Stderr, "%+v\n", e)
}
}
return nil
},
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ package cmd
import (
"encoding/json"
"fmt"
"os"
"os/signal"

giDevice "github.com/SonicCloudOrg/sonic-gidevice"
"github.com/SonicCloudOrg/sonic-ios-bridge/src/entity"
"github.com/SonicCloudOrg/sonic-ios-bridge/src/util"
"github.com/spf13/cobra"
"os"
"os/signal"
)

var listenCmd = &cobra.Command{
Expand Down Expand Up @@ -62,9 +63,10 @@ var listenCmd = &cobra.Command{
if device.Status == "online" && isDetail {
detail, err1 := entity.GetDetail(d)
if err1 != nil {
continue
fmt.Fprintf(os.Stderr, "%+v\n", err1)
} else {
device.DeviceDetail = *detail
}
device.DeviceDetail = *detail
}
data := util.ResultData(device)
fmt.Println(util.Format(data, isFormat, isDetail))
Expand Down

0 comments on commit 9ffd12c

Please sign in to comment.