Browse Source

Use regexes instead of substrings when searching

pull/8/head
Daniel Martí 11 years ago
parent
commit
7e9173b931
  1. 20
      README.md
  2. 12
      cmd/fdroidcl/main.go
  3. 14
      cmd/fdroidcl/search.go

20
README.md

@ -9,19 +9,19 @@ devices via [ADB](https://developer.android.com/tools/help/adb.html).
### Commands
update Update the index
list List all available apps
search <term...> Search available apps
show <app...> Show detailed info about an app
devices List connected devices
installed List installed apps
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
installed List installed apps
### Missing commands
updates List apps to update
install <app...> Install an app
upgrade <app...> Upgrade an app
remove <app...> Remove an app
updates List apps to update
install <appid...> Install an app
upgrade <appid...> Upgrade an app
remove <appid...> Remove an app
### Missing features

12
cmd/fdroidcl/main.go

@ -37,12 +37,12 @@ func init() {
fmt.Fprintln(os.Stderr, "Usage: fdroidcl [-h] <command> [<args>]")
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Available commands:")
fmt.Fprintln(os.Stderr, " update Update the index")
fmt.Fprintln(os.Stderr, " list List all available apps")
fmt.Fprintln(os.Stderr, " search <term...> Search available apps")
fmt.Fprintln(os.Stderr, " show <appid...> Show detailed info of an app")
fmt.Fprintln(os.Stderr, " devices List connected devices")
fmt.Fprintln(os.Stderr, " installed List installed apps")
fmt.Fprintln(os.Stderr, " update Update the index")
fmt.Fprintln(os.Stderr, " list List all available apps")
fmt.Fprintln(os.Stderr, " search <regexp...> Search available apps")
fmt.Fprintln(os.Stderr, " show <appid...> Show detailed info of an app")
fmt.Fprintln(os.Stderr, " devices List connected devices")
fmt.Fprintln(os.Stderr, " installed List installed apps")
}
}

14
cmd/fdroidcl/search.go

@ -4,6 +4,7 @@
package main
import (
"regexp"
"strings"
"github.com/mvdan/fdroidcl"
@ -25,8 +26,9 @@ func runSearch(args []string) {
}
func filterAppsSearch(apps []fdroidcl.App, terms []string) []fdroidcl.App {
for _, term := range terms {
term = strings.ToLower(term)
regexes := make([]*regexp.Regexp, len(terms))
for i, term := range terms {
regexes[i] = regexp.MustCompile(term)
}
var result []fdroidcl.App
for _, app := range apps {
@ -36,7 +38,7 @@ func filterAppsSearch(apps []fdroidcl.App, terms []string) []fdroidcl.App {
strings.ToLower(app.Summary),
strings.ToLower(app.Desc),
}
if !appMatches(fields, terms) {
if !appMatches(fields, regexes) {
continue
}
result = append(result, app)
@ -44,11 +46,11 @@ func filterAppsSearch(apps []fdroidcl.App, terms []string) []fdroidcl.App {
return result
}
func appMatches(fields []string, terms []string) bool {
func appMatches(fields []string, regexes []*regexp.Regexp) bool {
fieldLoop:
for _, field := range fields {
for _, term := range terms {
if !strings.Contains(field, term) {
for _, regex := range regexes {
if !regex.MatchString(field) {
continue fieldLoop
}
}

Loading…
Cancel
Save