Skip to content

Commit

Permalink
afc微调
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Jul 24, 2022
1 parent 5b5d8a3 commit 66205fe
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 110 deletions.
25 changes: 20 additions & 5 deletions cmd/afc.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
/*
* 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 cmd

import (
"github.com/SonicCloudOrg/sonic-ios-bridge/cmd/afcUtil"
"github.com/SonicCloudOrg/sonic-ios-bridge/cmd/afc"
"github.com/spf13/cobra"
)

var afcCmd = &cobra.Command{
Use: "afc",
Short: "manipulate device files through afc commands",
Long: "manipulate device files through afc commands",
RunE: func(cmd *cobra.Command, args []string) error {
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
return nil
},
}

func init() {
func init() {
rootCmd.AddCommand(afcCmd)
afcUtil.InitAfc(afcCmd)
afc.InitAfc(afcCmd)
}
31 changes: 23 additions & 8 deletions cmd/afcUtil/afcInit.go → cmd/afc/afcInit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package afcUtil
/*
* 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 afc

import (
"fmt"
Expand All @@ -8,14 +24,13 @@ import (
"os"
)

var afcRootCMD *cobra.Command

var afcRootCMD *cobra.Command

var udid string
var bundleID string
var udid string
var bundleID string

// InitAfc 用于初始化,在上层中调用这个方法,否则不会正常进行初始化
func InitAfc(afcCMD *cobra.Command){
func InitAfc(afcCMD *cobra.Command) {
afcRootCMD = afcCMD

initMkDir()
Expand All @@ -32,7 +47,7 @@ func InitAfc(afcCMD *cobra.Command){
initRMTree()
}

func getAFCServer()(afcServer giDevice.Afc) {
func getAFCServer() (afcServer giDevice.Afc) {
device := util.GetDeviceByUdId(udid)
if device == nil {
os.Exit(0)
Expand All @@ -54,4 +69,4 @@ func getAFCServer()(afcServer giDevice.Afc) {
os.Exit(0)
}
return afcServer
}
}
22 changes: 19 additions & 3 deletions cmd/afcUtil/cat.go → cmd/afc/cat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package afcUtil
/*
* 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 afc

import (
"fmt"
Expand All @@ -13,7 +29,7 @@ var afcCatCmd = &cobra.Command{
Short: "cat to view files",
Long: "cat to view files",
RunE: func(cmd *cobra.Command, args []string) error {
afcServer:=getAFCServer()
afcServer := getAFCServer()
catFile(afcServer, catFilePath)
return nil
},
Expand All @@ -25,7 +41,7 @@ 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(&catFilePath, "file", "f","", "cat file path")
afcCatCmd.Flags().StringVarP(&catFilePath, "file", "f", "", "cat file path")
afcCatCmd.MarkFlagRequired("file")
}

Expand Down
24 changes: 20 additions & 4 deletions cmd/afcUtil/ls.go → cmd/afc/ls.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package afcUtil
/*
* 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 afc

import (
"fmt"
Expand All @@ -13,7 +29,7 @@ var afcLsCmd = &cobra.Command{
Short: "ls to view the directory",
Long: "ls to view the directory",
RunE: func(cmd *cobra.Command, args []string) error {
afcServer:=getAFCServer()
afcServer := getAFCServer()
lsShow(afcServer, lsDirPath)
return nil
},
Expand All @@ -25,7 +41,7 @@ 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(&lsDirPath,"folder", "f","", "ls folder path")
afcLsCmd.Flags().StringVarP(&lsDirPath, "folder", "f", "", "ls folder path")
afcLsCmd.MarkFlagRequired("folder")
}

Expand All @@ -50,4 +66,4 @@ func lsShow(afc giDevice.Afc, filePath string) {
fmt.Println(fmt.Sprintf("- %s %d", fileName, info.Size()))
}
}
}
}
49 changes: 49 additions & 0 deletions cmd/afc/mkdir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 afc

import (
"fmt"
"github.com/spf13/cobra"
"os"
)

var afcMkDirCmd = &cobra.Command{
Use: "mkdir",
Short: "create a directory",
Long: "create a directory",
RunE: func(cmd *cobra.Command, args []string) error {
afcServer := getAFCServer()
err := (afcServer).Mkdir(mkDir)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
fmt.Println("mkdir success")
return nil
},
}

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(&mkDir, "folder", "f", "", "mkdir directory path")
afcMkDirCmd.MarkFlagRequired("folder")
}
29 changes: 23 additions & 6 deletions cmd/afcUtil/pull.go → cmd/afc/pull.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package afcUtil
/*
* 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 afc

import (
"fmt"
Expand All @@ -14,21 +30,22 @@ var afcPullCmd = &cobra.Command{
Short: "pull file or directory from device",
Long: "pull file or directory from device",
RunE: func(cmd *cobra.Command, args []string) error {
afcServer:=getAFCServer()
afcServer := getAFCServer()
pullOperate(afcServer, pullDevicePath, pullSaveLocalPath)
fmt.Println(fmt.Sprintf("success,pull %s --> %s", pullDevicePath, pullSaveLocalPath))
return nil
},
}

var pullDevicePath string
var pullSaveLocalPath string
var pullDevicePath string
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(&pullDevicePath,"devicePath", "d","", "pull file or directory device path")
afcPullCmd.Flags().StringVarP(&pullSaveLocalPath,"localPath", "l","", "pull save file or directory to local path")
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")
afcPullCmd.MarkFlagRequired("localPath")
}
Expand Down
27 changes: 21 additions & 6 deletions cmd/afcUtil/push.go → cmd/afc/push.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package afcUtil
/*
* 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 afc

import (
"fmt"
Expand All @@ -14,23 +30,23 @@ var afcPushCmd = &cobra.Command{
Short: "push a file or directory to the device",
Long: "push a file or directory to the device",
RunE: func(cmd *cobra.Command, args []string) error {
afcServer:=getAFCServer()
afcServer := getAFCServer()
pushOperate(afcServer, pushLocalPath, pushSaveDevicePath)
fmt.Println(fmt.Sprintf("success,push %s --> %s", pushLocalPath, pushSaveDevicePath))

return nil
},
}

var pushLocalPath string
var pushLocalPath string
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(&pushLocalPath,"localPath", "l","", "push file or directory local path")
afcPushCmd.Flags().StringVarP(&pushSaveDevicePath,"devicePath", "d","", "push save file or directory to device path")
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")
afcPushCmd.MarkFlagRequired("devicePath")
}
Expand Down Expand Up @@ -85,4 +101,3 @@ func pushOperate(afc giDevice.Afc, localPath string, devicePath string) {
pushFile(afc, localPath, devicePath)
}
}

49 changes: 49 additions & 0 deletions cmd/afc/rm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 afc

import (
"fmt"
"github.com/spf13/cobra"
"os"
)

var afcRMCmd = &cobra.Command{
Use: "rm",
Short: "delete file",
Long: "delete file",
RunE: func(cmd *cobra.Command, args []string) error {
afcServer := getAFCServer()
err := (afcServer).Remove(rmFilePath)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
fmt.Println("rm success")
return nil
},
}

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(&rmFilePath, "file", "f", "", "the address of the file to be deleted")
afcRMCmd.MarkFlagRequired("file")
}
Loading

0 comments on commit 66205fe

Please sign in to comment.