Browse Source

Remove list in favour of search

list was just a search without arguments anyway
pull/8/head
Daniel Martí 11 years ago
parent
commit
25e15bb75b
  1. 1
      README.md
  2. 66
      cmd/fdroidcl/list.go
  3. 1
      cmd/fdroidcl/main.go
  4. 41
      cmd/fdroidcl/search.go

1
README.md

@ -10,7 +10,6 @@ devices via [ADB](https://developer.android.com/tools/help/adb.html).
### Commands
update Update the index
list List all available apps
search <regexp...> Search available apps
show <appid...> Show detailed info about an app
devices List connected devices

66
cmd/fdroidcl/list.go

@ -1,66 +0,0 @@
/* Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc> */
/* See LICENSE for licensing information */
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/mvdan/fdroidcl"
)
var cmdList = &Command{
UsageLine: "list",
Short: "List all available apps",
}
func init() {
cmdList.Run = runList
}
func runList(args []string) {
index := mustLoadIndex()
printApps(index.Apps)
}
func mustLoadIndex() *fdroidcl.Index {
p := indexPath(repoName)
f, err := os.Open(p)
if err != nil {
log.Fatalf("Could not open index file: %v", err)
}
stat, err := f.Stat()
if err != nil {
log.Fatalf("Could not stat index file: %v", err)
}
//pubkey, err := hex.DecodeString(repoPubkey)
//if err != nil {
// log.Fatalf("Could not decode public key: %v", err)
//}
index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil)
if err != nil {
log.Fatalf("Could not load index: %v", err)
}
return index
}
func printApps(apps []fdroidcl.App) {
maxIDLen := 0
for _, app := range apps {
if len(app.ID) > maxIDLen {
maxIDLen = len(app.ID)
}
}
for _, app := range apps {
printApp(app, maxIDLen)
}
}
func printApp(app fdroidcl.App, IDLen int) {
fmt.Printf("%s%s %s %s\n", app.ID, strings.Repeat(" ", IDLen-len(app.ID)),
app.Name, app.CurApk.VName)
fmt.Printf(" %s\n", app.Summary)
}

1
cmd/fdroidcl/main.go

@ -78,7 +78,6 @@ func init() {
// Commands lists the available commands.
var commands = []*Command{
cmdUpdate,
cmdList,
cmdSearch,
cmdShow,
cmdDevices,

41
cmd/fdroidcl/search.go

@ -5,6 +5,8 @@ package main
import (
"fmt"
"log"
"os"
"regexp"
"strings"
@ -36,6 +38,27 @@ func runSearch(args []string) {
}
}
func mustLoadIndex() *fdroidcl.Index {
p := indexPath(repoName)
f, err := os.Open(p)
if err != nil {
log.Fatalf("Could not open index file: %v", err)
}
stat, err := f.Stat()
if err != nil {
log.Fatalf("Could not stat index file: %v", err)
}
//pubkey, err := hex.DecodeString(repoPubkey)
//if err != nil {
// log.Fatalf("Could not decode public key: %v", err)
//}
index, err := fdroidcl.LoadIndexJar(f, stat.Size(), nil)
if err != nil {
log.Fatalf("Could not load index: %v", err)
}
return index
}
func filterAppsSearch(apps []fdroidcl.App, terms []string) []fdroidcl.App {
regexes := make([]*regexp.Regexp, len(terms))
for i, term := range terms {
@ -69,3 +92,21 @@ fieldLoop:
}
return false
}
func printApps(apps []fdroidcl.App) {
maxIDLen := 0
for _, app := range apps {
if len(app.ID) > maxIDLen {
maxIDLen = len(app.ID)
}
}
for _, app := range apps {
printApp(app, maxIDLen)
}
}
func printApp(app fdroidcl.App, IDLen int) {
fmt.Printf("%s%s %s %s\n", app.ID, strings.Repeat(" ", IDLen-len(app.ID)),
app.Name, app.CurApk.VName)
fmt.Printf(" %s\n", app.Summary)
}

Loading…
Cancel
Save