feat: reboot or shutdown ios device

This commit is contained in:
debugtalk
2022-10-01 23:58:48 +08:00
parent 328ddb5309
commit 84c88d7dde
3 changed files with 43 additions and 4 deletions

View File

@@ -3,8 +3,9 @@ package adb
import "github.com/spf13/cobra"
var androidRootCmd = &cobra.Command{
Use: "adb",
Short: "simple utils for android device management",
Use: "adb",
Short: "simple utils for android device management",
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
}
func Init(rootCmd *cobra.Command) {

View File

@@ -11,8 +11,9 @@ import (
)
var iosRootCmd = &cobra.Command{
Use: "ios",
Short: "simple utils for ios device management",
Use: "ios",
Short: "simple utils for ios device management",
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
}
func getDevice(udid string) (giDevice.Device, error) {

37
hrp/cmd/ios/reboot.go Normal file
View File

@@ -0,0 +1,37 @@
package ios
import (
"fmt"
"github.com/spf13/cobra"
)
var rebootCmd = &cobra.Command{
Use: "reboot",
Short: "reboot or shutdown ios device",
RunE: func(cmd *cobra.Command, args []string) error {
device, err := getDevice(udid)
if err != nil {
return err
}
if isShutdown {
err = device.Shutdown()
} else {
err = device.Reboot()
}
if err != nil {
return err
}
fmt.Printf("reboot %s success\n", device.Properties().UDID)
return nil
},
}
var isShutdown bool
func init() {
rebootCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
rebootCmd.Flags().BoolVarP(&isShutdown, "shutdown", "s", false, "shutdown ios device")
iosRootCmd.AddCommand(rebootCmd)
}