Browse Source

feat: add searching by repository

master
Thomas Dickson 4 months ago
parent
commit
29d3bf60ab
  1. 28
      search.go

28
search.go

@ -27,6 +27,7 @@ var (
searchUpdates = cmdSearch.Fset.Bool("u", false, "Filter apps with updates") searchUpdates = cmdSearch.Fset.Bool("u", false, "Filter apps with updates")
searchDays = cmdSearch.Fset.Int("d", 0, "Select apps last updated in the last <n> days; a negative value drops them instead") searchDays = cmdSearch.Fset.Int("d", 0, "Select apps last updated in the last <n> days; a negative value drops them instead")
searchCategory = cmdSearch.Fset.String("c", "", "Filter apps by category") searchCategory = cmdSearch.Fset.String("c", "", "Filter apps by category")
searchRepo = cmdSearch.Fset.String("r", "", "Filter apps by repository")
searchSortBy = cmdSearch.Fset.String("o", "", "Sort order (added, updated)") searchSortBy = cmdSearch.Fset.String("o", "", "Sort order (added, updated)")
searchUser = cmdSearch.Fset.String("user", "all", "Filter installed apps by user <USER_ID|current|all>") searchUser = cmdSearch.Fset.String("user", "all", "Filter installed apps by user <USER_ID|current|all>")
) )
@ -47,10 +48,18 @@ func runSearch(args []string) error {
if err != nil { if err != nil {
return err return err
} }
if len(apps) > 0 && *searchCategory != "" { if len(apps) > 0 {
apps = filterAppsCategory(apps, *searchCategory) if *searchCategory != "" {
if apps == nil { apps = filterAppsCategory(apps, *searchCategory)
return fmt.Errorf("no such category: %s", *searchCategory) if apps == nil {
return fmt.Errorf("no such category: %s", *searchCategory)
}
}
if *searchRepo != "" {
apps = filterAppsRepo(apps, *searchRepo)
if apps == nil {
return fmt.Errorf("no such repository: %s", *searchRepo)
}
} }
} }
if len(apps) > 0 && len(args) > 0 { if len(apps) > 0 && len(args) > 0 {
@ -263,6 +272,17 @@ func contains(l []string, s string) bool {
return false return false
} }
func filterAppsRepo(apps []fdroid.App, repo string) []fdroid.App {
var result []fdroid.App
for _, app := range apps {
if app.FdroidRepoName != repo {
continue
}
result = append(result, app)
}
return result
}
func filterAppsCategory(apps []fdroid.App, categ string) []fdroid.App { func filterAppsCategory(apps []fdroid.App, categ string) []fdroid.App {
var result []fdroid.App var result []fdroid.App
for _, app := range apps { for _, app := range apps {

Loading…
Cancel
Save