diff --git a/cmd/fdroidcl/search.go b/cmd/fdroidcl/search.go index ab0b5c7..5ea4f0e 100644 --- a/cmd/fdroidcl/search.go +++ b/cmd/fdroidcl/search.go @@ -20,7 +20,8 @@ var cmdSearch = &Command{ var ( quiet = cmdSearch.Flag.Bool("q", false, "Print package names only") - installed = cmdSearch.Flag.Bool("i", false, "Filter installed packages") + installed = cmdSearch.Flag.Bool("i", false, "Filter installed apps") + updates = cmdSearch.Flag.Bool("u", false, "Filter apps with updates") ) func init() { @@ -30,11 +31,20 @@ func init() { func runSearch(args []string) { index := mustLoadIndex() apps := filterAppsSearch(index.Apps, args) + if *installed && *updates { + fmt.Println("-i and -u at the same time don't make sense") + cmdSearch.Flag.Usage() + } if *installed { device := oneDevice() installed := mustInstalled(device) apps = filterAppsInstalled(apps, installed) } + if *updates { + device := oneDevice() + installed := mustInstalled(device) + apps = filterAppsUpdates(apps, installed) + } if *quiet { for _, app := range apps { fmt.Println(app.ID) @@ -118,3 +128,23 @@ func filterAppsInstalled(apps []fdroidcl.App, installed []adb.Package) []fdroidc } return result } + +func filterAppsUpdates(apps []fdroidcl.App, installed []adb.Package) []fdroidcl.App { + instMap := make(map[string]*adb.Package, len(installed)) + for i := range installed { + p := &installed[i] + instMap[p.ID] = p + } + var result []fdroidcl.App + for _, app := range apps { + p, e := instMap[app.ID] + if !e { + continue + } + if p.VCode >= app.CurApk.VCode { + continue + } + result = append(result, app) + } + return result +}