diff --git a/README.md b/README.md index aadbda7..4ade670 100644 --- a/README.md +++ b/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 Search available apps show Show detailed info about an app devices List connected devices diff --git a/cmd/fdroidcl/list.go b/cmd/fdroidcl/list.go deleted file mode 100644 index 2158602..0000000 --- a/cmd/fdroidcl/list.go +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (c) 2015, Daniel Martí */ -/* 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) -} diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index 0b4e629..3938c71 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -78,7 +78,6 @@ func init() { // Commands lists the available commands. var commands = []*Command{ cmdUpdate, - cmdList, cmdSearch, cmdShow, cmdDevices, diff --git a/cmd/fdroidcl/search.go b/cmd/fdroidcl/search.go index d7d5b53..bc4f04d 100644 --- a/cmd/fdroidcl/search.go +++ b/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) +}