diff --git a/cmd/afc/afcInit.go b/cmd/afc/afcInit.go index 9d40151..39d9b46 100644 --- a/cmd/afc/afcInit.go +++ b/cmd/afc/afcInit.go @@ -26,8 +26,7 @@ import ( var afcRootCMD *cobra.Command -var udid string -var bundleID string +var udid, bundleId string // InitAfc 用于初始化,在上层中调用这个方法,否则不会正常进行初始化 func InitAfc(afcCMD *cobra.Command) { @@ -53,14 +52,14 @@ func getAFCServer() (afcServer giDevice.Afc) { os.Exit(0) } var err error - if bundleID != "" { + if bundleId != "" { var houseArrestSrv giDevice.HouseArrest houseArrestSrv, err = device.HouseArrestService() if err != nil { fmt.Println(err) os.Exit(0) } - afcServer, err = houseArrestSrv.Documents(bundleID) + afcServer, err = houseArrestSrv.Documents(bundleId) } else { afcServer, err = device.AfcService() } diff --git a/cmd/afc/cat.go b/cmd/afc/cat.go index 1adfbd2..226d004 100644 --- a/cmd/afc/cat.go +++ b/cmd/afc/cat.go @@ -40,7 +40,7 @@ var catFilePath string func initCat() { afcRootCMD.AddCommand(afcCatCmd) afcCatCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcCatCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcCatCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcCatCmd.Flags().StringVarP(&catFilePath, "file", "f", "", "cat file path") afcCatCmd.MarkFlagRequired("file") } diff --git a/cmd/afc/ls.go b/cmd/afc/ls.go index ac54505..d7d55cd 100644 --- a/cmd/afc/ls.go +++ b/cmd/afc/ls.go @@ -40,7 +40,7 @@ var lsDirPath string func initLs() { afcRootCMD.AddCommand(afcLsCmd) afcLsCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcLsCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcLsCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcLsCmd.Flags().StringVarP(&lsDirPath, "folder", "f", "", "ls folder path") afcLsCmd.MarkFlagRequired("folder") } diff --git a/cmd/afc/mkdir.go b/cmd/afc/mkdir.go index c264797..8e5f379 100644 --- a/cmd/afc/mkdir.go +++ b/cmd/afc/mkdir.go @@ -43,7 +43,7 @@ var mkDir string func initMkDir() { afcRootCMD.AddCommand(afcMkDirCmd) afcMkDirCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcMkDirCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcMkDirCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcMkDirCmd.Flags().StringVarP(&mkDir, "folder", "f", "", "mkdir directory path") afcMkDirCmd.MarkFlagRequired("folder") } diff --git a/cmd/afc/pull.go b/cmd/afc/pull.go index 78e96a7..18338d9 100644 --- a/cmd/afc/pull.go +++ b/cmd/afc/pull.go @@ -43,7 +43,7 @@ var pullSaveLocalPath string func initPullCmd() { afcRootCMD.AddCommand(afcPullCmd) afcPullCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcPullCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcPullCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcPullCmd.Flags().StringVarP(&pullDevicePath, "devicePath", "d", "", "pull file or directory device path") afcPullCmd.Flags().StringVarP(&pullSaveLocalPath, "localPath", "l", "", "pull save file or directory to local path") afcPullCmd.MarkFlagRequired("devicePath") diff --git a/cmd/afc/push.go b/cmd/afc/push.go index 43358fd..0b946bc 100644 --- a/cmd/afc/push.go +++ b/cmd/afc/push.go @@ -44,7 +44,7 @@ var pushSaveDevicePath string func initPush() { afcRootCMD.AddCommand(afcPushCmd) afcPushCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcPushCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcPushCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcPushCmd.Flags().StringVarP(&pushLocalPath, "localPath", "l", "", "push file or directory local path") afcPushCmd.Flags().StringVarP(&pushSaveDevicePath, "devicePath", "d", "", "push save file or directory to device path") afcPushCmd.MarkFlagRequired("localPath") diff --git a/cmd/afc/rm.go b/cmd/afc/rm.go index b5e04d1..8902a30 100644 --- a/cmd/afc/rm.go +++ b/cmd/afc/rm.go @@ -43,7 +43,7 @@ var rmFilePath string func initRM() { afcRootCMD.AddCommand(afcRMCmd) afcRMCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcRMCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcRMCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcRMCmd.Flags().StringVarP(&rmFilePath, "file", "f", "", "the address of the file to be deleted") afcRMCmd.MarkFlagRequired("file") } diff --git a/cmd/afc/rmtree.go b/cmd/afc/rmtree.go index 1847812..5d8cf20 100644 --- a/cmd/afc/rmtree.go +++ b/cmd/afc/rmtree.go @@ -41,7 +41,7 @@ var rmDir string func initRMTree() { afcRootCMD.AddCommand(afcRMTreeCmd) afcRMTreeCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcRMTreeCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcRMTreeCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcRMTreeCmd.Flags().StringVarP(&rmDir, "folder", "f", "", "folder address to delete") afcRMTreeCmd.MarkFlagRequired("folder") } diff --git a/cmd/afc/stat.go b/cmd/afc/stat.go index e538c1a..c571580 100644 --- a/cmd/afc/stat.go +++ b/cmd/afc/stat.go @@ -49,7 +49,7 @@ var statPath string func initStat() { afcRootCMD.AddCommand(afcStatCmd) afcStatCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcStatCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcStatCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcStatCmd.Flags().StringVarP(&statPath, "path", "p", "", "files or folders for which details need to be viewed") afcStatCmd.MarkFlagRequired("path") } diff --git a/cmd/afc/tree.go b/cmd/afc/tree.go index de03a1b..8d68e79 100644 --- a/cmd/afc/tree.go +++ b/cmd/afc/tree.go @@ -40,7 +40,7 @@ var treeDir string func initTree() { afcRootCMD.AddCommand(afcTreeCmd) afcTreeCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )") - afcTreeCmd.Flags().StringVarP(&bundleID, "bundleId", "b", "", "app bundleId") + afcTreeCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "app bundleId") afcTreeCmd.Flags().StringVarP(&treeDir, "folder", "f", "", "folder path to tree view") afcTreeCmd.MarkFlagRequired("folder") } diff --git a/cmd/app.go b/cmd/app.go index 76ad713..520a84b 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -17,6 +17,7 @@ package cmd import ( + "github.com/SonicCloudOrg/sonic-ios-bridge/cmd/app" "github.com/spf13/cobra" ) @@ -31,4 +32,5 @@ var appCmd = &cobra.Command{ func init() { rootCmd.AddCommand(appCmd) + app.InitApp(appCmd) } diff --git a/cmd/app/appInit.go b/cmd/app/appInit.go new file mode 100644 index 0000000..d386dbb --- /dev/null +++ b/cmd/app/appInit.go @@ -0,0 +1,31 @@ +/* + * Copyright (C) [SonicCloudOrg] Sonic Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package app + +import "github.com/spf13/cobra" + +var appRootCMD *cobra.Command + +var udid, bundleId string +var isJson, isDetail, isFormat bool + +func InitApp(appCMD *cobra.Command) { + appRootCMD = appCMD + + initAppInstall() + initAppList() +} diff --git a/cmd/install.go b/cmd/app/install.go similarity index 95% rename from cmd/install.go rename to cmd/app/install.go index 4d11802..19e3215 100644 --- a/cmd/install.go +++ b/cmd/app/install.go @@ -14,7 +14,7 @@ * limitations under the License. * */ -package cmd +package app import ( "fmt" @@ -44,8 +44,8 @@ var installCmd = &cobra.Command{ var path string -func init() { - appCmd.AddCommand(installCmd) +func initAppInstall() { + appRootCMD.AddCommand(installCmd) installCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber") installCmd.Flags().StringVarP(&path, "path", "p", "", "path of ipa file") installCmd.MarkFlagRequired("path") diff --git a/cmd/list.go b/cmd/app/list.go similarity index 97% rename from cmd/list.go rename to cmd/app/list.go index c148d4c..d78cb68 100644 --- a/cmd/list.go +++ b/cmd/app/list.go @@ -14,7 +14,7 @@ * limitations under the License. * */ -package cmd +package app import ( "encoding/base64" @@ -91,8 +91,8 @@ var listCmd = &cobra.Command{ var showIcon bool -func init() { - appCmd.AddCommand(listCmd) +func initAppList() { + appRootCMD.AddCommand(listCmd) listCmd.Flags().BoolVarP(&showIcon, "icon", "i", false, "show app icon") listCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber") listCmd.Flags().BoolVarP(&isJson, "json", "j", false, "convert to JSON string") diff --git a/cmd/crash.go b/cmd/crash.go index 1fd6268..5d31b3f 100644 --- a/cmd/crash.go +++ b/cmd/crash.go @@ -34,14 +34,14 @@ var crashCmd = &cobra.Command{ if device == nil { os.Exit(0) } - if !filepath.IsAbs(path) { + if !filepath.IsAbs(crashOutputPath) { var err error - if path, err = filepath.Abs(path); err != nil { + if crashOutputPath, err = filepath.Abs(crashOutputPath); err != nil { fmt.Println("path no found!") os.Exit(0) } } - err := device.MoveCrashReport(path, + err := device.MoveCrashReport(crashOutputPath, giDevice.WithKeepCrashReport(keep), giDevice.WithExtractRawCrashReport(true), giDevice.WithWhenMoveIsDone(func(filename string) { @@ -57,10 +57,11 @@ var crashCmd = &cobra.Command{ } var keep bool +var crashOutputPath string func init() { rootCmd.AddCommand(crashCmd) crashCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber (default first device)") crashCmd.Flags().BoolVarP(&keep, "keep", "k", false, "keep crash reports from device") - crashCmd.Flags().StringVarP(&path, "path", "p", "./", "output path") + crashCmd.Flags().StringVarP(&crashOutputPath, "path", "p", "./", "output path") }