From 921894b43b50a4030fa3725c86f446f1aca9d043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 18 Jun 2015 19:51:32 +0200 Subject: [PATCH] Replace installed command by -i flag in search --- README.md | 2 -- cmd/fdroidcl/installed.go | 52 --------------------------------------- cmd/fdroidcl/main.go | 1 - cmd/fdroidcl/search.go | 33 ++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 56 deletions(-) delete mode 100644 cmd/fdroidcl/installed.go diff --git a/README.md b/README.md index 4ade670..5cd1bd5 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,9 @@ devices via [ADB](https://developer.android.com/tools/help/adb.html). search Search available apps show Show detailed info about an app devices List connected devices - installed List installed apps ### Missing commands - updates List apps to update install Install an app upgrade Upgrade an app remove Remove an app diff --git a/cmd/fdroidcl/installed.go b/cmd/fdroidcl/installed.go deleted file mode 100644 index 3e8db3c..0000000 --- a/cmd/fdroidcl/installed.go +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (c) 2015, Daniel Martí */ -/* See LICENSE for licensing information */ - -package main - -import ( - "log" - - "github.com/mvdan/fdroidcl" - "github.com/mvdan/fdroidcl/adb" -) - -var cmdInstalled = &Command{ - UsageLine: "installed", - Short: "List installed apps", -} - -func init() { - cmdInstalled.Run = runInstalled -} - -func runInstalled(args []string) { - index := mustLoadIndex() - startAdbIfNeeded() - device := oneDevice() - installed := mustInstalled(device) - apps := filterAppsInstalled(index.Apps, installed) - printApps(apps) -} - -func mustInstalled(device adb.Device) []string { - installed, err := device.Installed() - if err != nil { - log.Fatalf("Could not get installed packages: %v", err) - } - return installed -} - -func filterAppsInstalled(apps []fdroidcl.App, installed []string) []fdroidcl.App { - instMap := make(map[string]struct{}, len(installed)) - for _, id := range installed { - instMap[id] = struct{}{} - } - var result []fdroidcl.App - for _, app := range apps { - if _, e := instMap[app.ID]; !e { - continue - } - result = append(result, app) - } - return result -} diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index 3938c71..867bbe0 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -81,7 +81,6 @@ var commands = []*Command{ cmdSearch, cmdShow, cmdDevices, - cmdInstalled, } func main() { diff --git a/cmd/fdroidcl/search.go b/cmd/fdroidcl/search.go index 953a505..add2079 100644 --- a/cmd/fdroidcl/search.go +++ b/cmd/fdroidcl/search.go @@ -5,10 +5,12 @@ package main import ( "fmt" + "log" "regexp" "strings" "github.com/mvdan/fdroidcl" + "github.com/mvdan/fdroidcl/adb" ) var cmdSearch = &Command{ @@ -17,7 +19,8 @@ var cmdSearch = &Command{ } var ( - quiet = cmdSearch.Flag.Bool("q", false, "Show package name only") + quiet = cmdSearch.Flag.Bool("q", false, "Show package name only") + installed = cmdSearch.Flag.Bool("i", false, "Filter installed packages") ) func init() { @@ -27,6 +30,11 @@ func init() { func runSearch(args []string) { index := mustLoadIndex() apps := filterAppsSearch(index.Apps, args) + if *installed { + device := oneDevice() + installed := mustInstalled(device) + apps = filterAppsInstalled(apps, installed) + } if *quiet { for _, app := range apps { fmt.Println(app.ID) @@ -87,3 +95,26 @@ func printApp(app fdroidcl.App, IDLen int) { app.Name, app.CurApk.VName) fmt.Printf(" %s\n", app.Summary) } + +func mustInstalled(device adb.Device) []string { + installed, err := device.Installed() + if err != nil { + log.Fatalf("Could not get installed packages: %v", err) + } + return installed +} + +func filterAppsInstalled(apps []fdroidcl.App, installed []string) []fdroidcl.App { + instMap := make(map[string]struct{}, len(installed)) + for _, id := range installed { + instMap[id] = struct{}{} + } + var result []fdroidcl.App + for _, app := range apps { + if _, e := instMap[app.ID]; !e { + continue + } + result = append(result, app) + } + return result +}