[Bug] 非常明显的一个bug devices命令使用-u无效
Opened this issue · 3 comments
Circlefork commented
Search before asking
- I searched in the issue and found nothing similar. | 我查找了并确认issue列表无相似报告。
Sonic version
全部
Deploy platform
全部
Minimal reproduce step
-u 选择设备没用
Are you willing to submit a PR?
- I'm willing to submit a PR! | 我将发起PR!
ZhouYixun commented
非常感谢你的热心反馈,很少看到有这么犀利的点评了,我们将在近期修复。楼主有能力也可以参与修复呢~
Circlefork commented
/*
* sonic-ios-bridge Connect to your iOS Devices.
* Copyright (C) 2022 SonicCloudOrg
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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"
)
var devicesCmd = &cobra.Command{
Use: "devices",
Short: "Get iOS device list",
Long: "Get iOS device list",
RunE: func(cmd *cobra.Command, args []string) error {
usbMuxClient, err := giDevice.NewUsbmux()
if err != nil {
return util.NewErrorPrint(util.ErrConnect, "usbMux", err)
}
list, err1 := usbMuxClient.Devices()
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{}
}
var deviceList entity.DeviceList
for _, d := range list {
if udid != "" {
// todo
if d.Properties().SerialNumber == udid {
device := &entity.Device{}
deviceByte, _ := json.Marshal(d.Properties())
if isDetail {
detail, err2 := entity.GetDetail(d)
if err2 != nil {
todosErrores = append(todosErrores, err2)
} else {
device.DeviceDetail = *detail
}
}
json.Unmarshal(deviceByte, device)
device.Status = device.GetStatus()
device.RemoteAddr = "localhost"
data := util.ResultData(device)
fmt.Println(util.Format(data, isFormat, isDetail))
return nil
}
} else {
deviceByte, _ := json.Marshal(d.Properties())
device := &entity.Device{}
if isDetail {
detail, err2 := entity.GetDetail(d)
if err2 != nil {
todosErrores = append(todosErrores, err2)
} else {
device.DeviceDetail = *detail
}
}
json.Unmarshal(deviceByte, device)
device.Status = device.GetStatus()
device.RemoteAddr = "localhost"
deviceList.DeviceList = append(deviceList.DeviceList, *device)
}
}
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 {
todosErrores = append(todosErrores, err2)
} else {
device.DeviceDetail = *detail
}
}
json.Unmarshal(deviceByte, device)
device.Status = device.GetStatus()
device.RemoteAddr = k
deviceList.DeviceList = append(deviceList.DeviceList, *device)
}
}
data := util.ResultData(deviceList)
fmt.Println(util.Format(data, isFormat, isDetail))
} else {
for _, v := range remoteList {
list = append(list, v)
}
if len(list) != 0 {
device := &entity.Device{}
for _, d := range list {
if d.Properties().SerialNumber == udid {
deviceByte, _ := json.Marshal(d.Properties())
if isDetail {
detail, err2 := entity.GetDetail(d)
if err2 != nil {
todosErrores = append(todosErrores, err2)
} else {
device.DeviceDetail = *detail
}
}
json.Unmarshal(deviceByte, device)
device.Status = device.GetStatus()
break
}
}
if device.SerialNumber != "" {
data := util.ResultData(device)
fmt.Println(util.Format(data, isFormat, isDetail))
} else {
fmt.Println("device not found")
os.Exit(0)
}
} else {
fmt.Println("no device connected")
os.Exit(0)
}
}
if len(todosErrores) > 0 {
for _, e := range todosErrores {
fmt.Fprintf(os.Stderr, "%+v\n", e)
}
}
return nil
},
}
func init() {
rootCmd.AddCommand(devicesCmd)
devicesCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber")
devicesCmd.Flags().BoolVarP(&isFormat, "format", "f", false, "convert to JSON string and format")
devicesCmd.Flags().BoolVarP(&isDetail, "detail", "d", false, "output every device's detail")
}
我简单的处理的一下
ZhouYixun commented
这样改麻烦了,后面我调整下逻辑