Browse Source

Split up app finding logic

pull/8/head
Daniel Martí 11 years ago
parent
commit
632a2050e7
  1. 23
      cmd/fdroidcl/show.go
  2. 5
      cmd/fdroidcl/update.go

23
cmd/fdroidcl/show.go

@ -24,9 +24,6 @@ func init() {
func runShow(args []string) {
apps := findApps(args)
for i, app := range apps {
if app == nil {
log.Fatalf("Could not find app with ID '%s'", args[i])
}
if i > 0 {
fmt.Printf("\n--\n\n")
}
@ -34,16 +31,24 @@ func runShow(args []string) {
}
}
func appsMap(apps []fdroidcl.App) map[string]*fdroidcl.App {
m := make(map[string]*fdroidcl.App, len(apps))
for i := range apps {
app := &apps[i]
m[app.ID] = app
}
return m
}
func findApps(ids []string) []*fdroidcl.App {
index := mustLoadIndex()
apps := make(map[string]*fdroidcl.App, len(index.Apps))
for i := range index.Apps {
app := &index.Apps[i]
apps[app.ID] = app
}
apps := appsMap(index.Apps)
result := make([]*fdroidcl.App, len(ids))
for i, id := range ids {
app, _ := apps[id]
app, e := apps[id]
if !e {
log.Fatalf("Could not find app with ID '%s'", id)
}
result[i] = app
}
return result

5
cmd/fdroidcl/update.go

@ -91,8 +91,9 @@ func indexPath(name string) string {
return filepath.Join(appSubdir(cache), repoName+".jar")
}
func appSubdir(appdir string) string {
p := filepath.Join(appdir, "fdroidcl")
func appSubdir(appdir string, subdir ...string) string {
elems := append([]string{appdir, "fdroidcl"}, subdir...)
p := filepath.Join(elems...)
if err := os.MkdirAll(p, 0755); err != nil {
log.Fatalf("Could not create app dir: %v", err)
}

Loading…
Cancel
Save