Browse Source

Replace installed command by -i flag in search

pull/8/head
Daniel Martí 11 years ago
parent
commit
921894b43b
  1. 2
      README.md
  2. 52
      cmd/fdroidcl/installed.go
  3. 1
      cmd/fdroidcl/main.go
  4. 33
      cmd/fdroidcl/search.go

2
README.md

@ -13,11 +13,9 @@ devices via [ADB](https://developer.android.com/tools/help/adb.html).
search <regexp...> Search available apps
show <appid...> Show detailed info about an app
devices List connected devices
installed List installed apps
### Missing commands
updates List apps to update
install <appid...> Install an app
upgrade <appid...> Upgrade an app
remove <appid...> Remove an app

52
cmd/fdroidcl/installed.go

@ -1,52 +0,0 @@
/* Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc> */
/* 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
}

1
cmd/fdroidcl/main.go

@ -81,7 +81,6 @@ var commands = []*Command{
cmdSearch,
cmdShow,
cmdDevices,
cmdInstalled,
}
func main() {

33
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
}

Loading…
Cancel
Save