Skip to content

Commit

Permalink
add avds wipe
Browse files Browse the repository at this point in the history
  • Loading branch information
esafirm committed Oct 22, 2020
1 parent e249bf2 commit 6378462
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ build:
buildbin:
go build -o $(BIN_PATH)
run:
@go run main.go avds
@go run main.go avds -w
5 changes: 5 additions & 0 deletions adb/adbcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func AvdRun(avdName string) {
cmd.Start()
}

// Wipe AVD emulator data
func AvdWipe(avdName string) {
runWithPrint("emulator", "@"+avdName, "-wipe-data{")
}

func DumpSys(moreCommand string) CommandReturn {
return runWithPrint("adb shell dumpsys " + moreCommand)
}
Expand Down
24 changes: 21 additions & 3 deletions cmd/avds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ import (
"github.com/spf13/cobra"
)

var isWipe bool

var avdsCmd = &cobra.Command{
Use: "avds [emulator name]",
Short: "List all available AVD(s) and run it",
Run: func(cmd *cobra.Command, args []string) {
if isWipe {
showAvdsWipe()
return
}

if len(args) == 0 {
showAvdSelection()
} else {
Expand All @@ -35,7 +42,18 @@ var avdsCmd = &cobra.Command{
},
}

func showAvdsWipe() {
result := showAvdsPrompt("Select AVD to be wiped")
adb.AvdWipe(result)
}

func showAvdSelection() {
result := showAvdsPrompt("Select AVD to run")
fmt.Printf("Launching %s AVD", result)
adb.AvdRun(result)
}

func showAvdsPrompt(caption string) string {
commandResult := adb.AvdList()
if commandResult.Error != nil {
panic(commandResult.Error)
Expand All @@ -45,7 +63,7 @@ func showAvdSelection() {
avdListSlice := strings.Split(avdList, "\n")

prompt := pui.Select{
Label: "Select AVD to run",
Label: caption,
Items: avdListSlice,
}

Expand All @@ -54,10 +72,10 @@ func showAvdSelection() {
panic(err)
}

fmt.Printf("Launching %s AVD", result)
adb.AvdRun(result)
return result
}

func init() {
rootCmd.AddCommand(avdsCmd)
avdsCmd.Flags().BoolVarP(&isWipe, "wipe", "w", false, "Wipe AVD data")
}

0 comments on commit 6378462

Please sign in to comment.