You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
999 B
Go

package cli
import (
"bufio"
"fmt"
"os/exec"
"strings"
)
type SibDevice struct {
UDID string `json:"udid"`
Status string `json:"status"`
Src string `json:"src"`
}
func GetIOSDevices() map[string]SibDevice {
m_devices := make(map[string]SibDevice)
cmd := exec.Command("sib", "devices")
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Println(err)
return m_devices
}
if err := cmd.Start(); err != nil {
fmt.Println(err)
return m_devices
}
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
output := scanner.Text()
if strings.Contains(output, "no device") {
// 没设备
return m_devices
}
if len(output) < 20 {
//空行
continue
}
if strs := strings.Fields(output); len(strs) >= 3 {
var d SibDevice
d.UDID = strs[0]
d.Status = strs[1]
d.Src = strs[2]
m_devices[d.UDID] = d
}
}
if err := scanner.Err(); err != nil {
return m_devices
}
if err := cmd.Wait(); err != nil {
return m_devices
}
return m_devices
}