diff --git a/README.md b/README.md index 532a4ec..33f9472 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,16 @@ devices via [ADB](https://developer.android.com/tools/help/adb.html). ### Commands - update Update the index - search Search available apps - show Show detailed info about an app - devices List connected devices + update Update the index + search Search available apps + show Show detailed info about an app + devices List connected devices + uninstall Uninstall an app ### Missing commands install Install an app upgrade Upgrade an app - remove Remove an app ### Missing features diff --git a/adb/adb.go b/adb/adb.go index c3618fa..dda4322 100644 --- a/adb/adb.go +++ b/adb/adb.go @@ -5,7 +5,9 @@ package adb import ( "bufio" + "errors" "fmt" + "io" "net" "os/exec" "regexp" @@ -17,6 +19,11 @@ const ( port = 5037 ) +var ( + ErrInternalError = errors.New("internal error") + ErrUnknown = errors.New("unknown error") +) + func IsServerRunning() bool { conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", "127.0.0.1", port)) if err != nil { @@ -32,7 +39,7 @@ func StartServer() error { if err != nil { return err } - return nil + return cmd.Wait() } type Device struct { @@ -102,15 +109,35 @@ func (d *Device) Install(path string) error { if err := cmd.Start(); err != nil { return err } - return nil + return cmd.Wait() +} + +func getLine(out io.ReadCloser) string { + scanner := bufio.NewScanner(out) + if !scanner.Scan() { + return "" + } + return scanner.Text() } func (d *Device) Uninstall(pkg string) error { cmd := d.AdbCmd("uninstall", pkg) + stdout, err := cmd.StdoutPipe() + if err != nil { + return err + } if err := cmd.Start(); err != nil { return err } - return nil + line := getLine(stdout) + if line == "Success" { + return nil + } + switch line { + case "Failure [DELETE_FAILED_INTERNAL_ERROR]": + return ErrInternalError + } + return ErrUnknown } type Package struct { diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index 867bbe0..4b673df 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -81,6 +81,7 @@ var commands = []*Command{ cmdSearch, cmdShow, cmdDevices, + cmdUninstall, } func main() { diff --git a/cmd/fdroidcl/uninstall.go b/cmd/fdroidcl/uninstall.go new file mode 100644 index 0000000..685a309 --- /dev/null +++ b/cmd/fdroidcl/uninstall.go @@ -0,0 +1,27 @@ +/* Copyright (c) 2015, Daniel Martí */ +/* See LICENSE for licensing information */ + +package main + +import "log" + +var cmdUninstall = &Command{ + UsageLine: "uninstall ", + Short: "Uninstall an app", +} + +func init() { + cmdUninstall.Run = runUninstall +} + +func runUninstall(args []string) { + if len(args) < 1 { + log.Fatalf("No package names given") + } + device := mustOneDevice() + for _, id := range args { + if err := device.Uninstall(id); err != nil { + log.Fatalf("Could not uninstall '%s': %v", id, err) + } + } +}