From e6a3f65f495916b008268fd26a5b1c9111db1e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 27 Jan 2019 00:01:45 +0000 Subject: [PATCH] move main package into root directory This way, users can simply do: go get mvdan.cc/fdroidcl Instead of the repetitive: go get mvdan.cc/fdroidcl/cmd/fdroidcl The cmd/... pattern only makes sense if the repository has many commands, or if the name of the repository and command don't match. Neither is the case here. --- README.md | 2 +- cmd/fdroidcl/defaults.go => defaults.go | 0 cmd/fdroidcl/devices.go => devices.go | 0 cmd/fdroidcl/download.go => download.go | 4 +- .../endtoend_test.go => endtoend_test.go | 0 fieldtypes.go => fdroid/fieldtypes.go | 2 +- index.go => fdroid/index.go | 2 +- index_test.go => fdroid/index_test.go | 2 +- jar.go => fdroid/jar.go | 2 +- cmd/fdroidcl/install.go => install.go | 10 ++--- cmd/fdroidcl/list.go => list.go | 0 cmd/fdroidcl/main.go => main.go | 0 cmd/fdroidcl/search.go => search.go | 40 +++++++++---------- cmd/fdroidcl/show.go => show.go | 14 +++---- cmd/fdroidcl/uninstall.go => uninstall.go | 0 cmd/fdroidcl/update.go => update.go | 18 ++++----- 16 files changed, 48 insertions(+), 48 deletions(-) rename cmd/fdroidcl/defaults.go => defaults.go (100%) rename cmd/fdroidcl/devices.go => devices.go (100%) rename cmd/fdroidcl/download.go => download.go (93%) rename cmd/fdroidcl/endtoend_test.go => endtoend_test.go (100%) rename fieldtypes.go => fdroid/fieldtypes.go (98%) rename index.go => fdroid/index.go (99%) rename index_test.go => fdroid/index_test.go (99%) rename jar.go => fdroid/jar.go (97%) rename cmd/fdroidcl/install.go => install.go (89%) rename cmd/fdroidcl/list.go => list.go (100%) rename cmd/fdroidcl/main.go => main.go (100%) rename cmd/fdroidcl/search.go => search.go (81%) rename cmd/fdroidcl/show.go => show.go (91%) rename cmd/fdroidcl/uninstall.go => uninstall.go (100%) rename cmd/fdroidcl/update.go => update.go (92%) diff --git a/README.md b/README.md index f82f467..520c2b8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [F-Droid](https://f-droid.org/) desktop client. - go get -u mvdan.cc/fdroidcl/cmd/fdroidcl + go get -u mvdan.cc/fdroidcl While the Android client integrates with the system with regular update checks and notifications, this is a simple command line client that talks to connected diff --git a/cmd/fdroidcl/defaults.go b/defaults.go similarity index 100% rename from cmd/fdroidcl/defaults.go rename to defaults.go diff --git a/cmd/fdroidcl/devices.go b/devices.go similarity index 100% rename from cmd/fdroidcl/devices.go rename to devices.go diff --git a/cmd/fdroidcl/download.go b/download.go similarity index 93% rename from cmd/fdroidcl/download.go rename to download.go index e69a653..4b7c3cb 100644 --- a/cmd/fdroidcl/download.go +++ b/download.go @@ -7,7 +7,7 @@ import ( "fmt" "path/filepath" - "mvdan.cc/fdroidcl" + "mvdan.cc/fdroidcl/fdroid" ) var cmdDownload = &Command{ @@ -45,7 +45,7 @@ func runDownload(args []string) error { return nil } -func downloadApk(apk *fdroidcl.Apk) (string, error) { +func downloadApk(apk *fdroid.Apk) (string, error) { url := apk.URL() path := apkPath(apk.ApkName) if err := downloadEtag(url, path, apk.Hash); err == errNotModified { diff --git a/cmd/fdroidcl/endtoend_test.go b/endtoend_test.go similarity index 100% rename from cmd/fdroidcl/endtoend_test.go rename to endtoend_test.go diff --git a/fieldtypes.go b/fdroid/fieldtypes.go similarity index 98% rename from fieldtypes.go rename to fdroid/fieldtypes.go index 1e2751e..cf3aa19 100644 --- a/fieldtypes.go +++ b/fdroid/fieldtypes.go @@ -1,7 +1,7 @@ // Copyright (c) 2015, Daniel Martí // See LICENSE for licensing information -package fdroidcl +package fdroid import ( "encoding/hex" diff --git a/index.go b/fdroid/index.go similarity index 99% rename from index.go rename to fdroid/index.go index 9d22ed6..9e11e64 100644 --- a/index.go +++ b/fdroid/index.go @@ -1,7 +1,7 @@ // Copyright (c) 2015, Daniel Martí // See LICENSE for licensing information -package fdroidcl +package fdroid import ( "encoding/json" diff --git a/index_test.go b/fdroid/index_test.go similarity index 99% rename from index_test.go rename to fdroid/index_test.go index c1bbf70..c5ecd44 100644 --- a/index_test.go +++ b/fdroid/index_test.go @@ -1,7 +1,7 @@ // Copyright (c) 2015, Daniel Martí // See LICENSE for licensing information -package fdroidcl +package fdroid import ( "bytes" diff --git a/jar.go b/fdroid/jar.go similarity index 97% rename from jar.go rename to fdroid/jar.go index 9dc4c42..6f5a07f 100644 --- a/jar.go +++ b/fdroid/jar.go @@ -1,7 +1,7 @@ // Copyright (c) 2015, Daniel Martí // See LICENSE for licensing information -package fdroidcl +package fdroid import ( "archive/zip" diff --git a/cmd/fdroidcl/install.go b/install.go similarity index 89% rename from cmd/fdroidcl/install.go rename to install.go index f059244..c4e5e3e 100644 --- a/cmd/fdroidcl/install.go +++ b/install.go @@ -6,8 +6,8 @@ package main import ( "fmt" - "mvdan.cc/fdroidcl" "mvdan.cc/fdroidcl/adb" + "mvdan.cc/fdroidcl/fdroid" ) var cmdInstall = &Command{ @@ -35,7 +35,7 @@ func runInstall(args []string) error { if err != nil { return err } - var toInstall []*fdroidcl.App + var toInstall []*fdroid.App for _, app := range apps { p, e := inst[app.PackageName] if !e { @@ -58,9 +58,9 @@ func runInstall(args []string) error { return downloadAndDo(toInstall, device) } -func downloadAndDo(apps []*fdroidcl.App, device *adb.Device) error { +func downloadAndDo(apps []*fdroid.App, device *adb.Device) error { type downloaded struct { - apk *fdroidcl.Apk + apk *fdroid.Apk path string } toInstall := make([]downloaded, len(apps)) @@ -83,7 +83,7 @@ func downloadAndDo(apps []*fdroidcl.App, device *adb.Device) error { return nil } -func installApk(device *adb.Device, apk *fdroidcl.Apk, path string) error { +func installApk(device *adb.Device, apk *fdroid.Apk, path string) error { fmt.Fprintf(stdout, "Installing %s\n", apk.AppID) if err := device.Install(path); err != nil { return fmt.Errorf("could not install %s: %v", apk.AppID, err) diff --git a/cmd/fdroidcl/list.go b/list.go similarity index 100% rename from cmd/fdroidcl/list.go rename to list.go diff --git a/cmd/fdroidcl/main.go b/main.go similarity index 100% rename from cmd/fdroidcl/main.go rename to main.go diff --git a/cmd/fdroidcl/search.go b/search.go similarity index 81% rename from cmd/fdroidcl/search.go rename to search.go index bf2f441..c1f4b35 100644 --- a/cmd/fdroidcl/search.go +++ b/search.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "mvdan.cc/fdroidcl" "mvdan.cc/fdroidcl/adb" + "mvdan.cc/fdroidcl/fdroid" ) var cmdSearch = &Command{ @@ -85,12 +85,12 @@ func runSearch(args []string) error { return nil } -func filterAppsSearch(apps []fdroidcl.App, terms []string) []fdroidcl.App { +func filterAppsSearch(apps []fdroid.App, terms []string) []fdroid.App { regexes := make([]*regexp.Regexp, len(terms)) for i, term := range terms { regexes[i] = regexp.MustCompile(term) } - var result []fdroidcl.App + var result []fdroid.App for _, app := range apps { fields := []string{ strings.ToLower(app.PackageName), @@ -119,7 +119,7 @@ fieldLoop: return false } -func printApps(apps []fdroidcl.App, inst map[string]adb.Package, device *adb.Device) { +func printApps(apps []fdroid.App, inst map[string]adb.Package, device *adb.Device) { maxIDLen := 0 for _, app := range apps { if len(app.PackageName) > maxIDLen { @@ -136,7 +136,7 @@ func printApps(apps []fdroidcl.App, inst map[string]adb.Package, device *adb.Dev } } -func descVersion(app fdroidcl.App, inst *adb.Package, device *adb.Device) string { +func descVersion(app fdroid.App, inst *adb.Package, device *adb.Device) string { if inst != nil { suggested := app.SuggestedApk(device) if suggested != nil && inst.VersCode < suggested.VersCode { @@ -148,14 +148,14 @@ func descVersion(app fdroidcl.App, inst *adb.Package, device *adb.Device) string return fmt.Sprintf("%s (%d)", app.SugVersName, app.SugVersCode) } -func printApp(app fdroidcl.App, IDLen int, inst *adb.Package, device *adb.Device) { +func printApp(app fdroid.App, IDLen int, inst *adb.Package, device *adb.Device) { fmt.Fprintf(stdout, "%s%s %s - %s\n", app.PackageName, strings.Repeat(" ", IDLen-len(app.PackageName)), app.Name, descVersion(app, inst, device)) fmt.Fprintf(stdout, " %s\n", app.Summary) } -func filterAppsInstalled(apps []fdroidcl.App, inst map[string]adb.Package) []fdroidcl.App { - var result []fdroidcl.App +func filterAppsInstalled(apps []fdroid.App, inst map[string]adb.Package) []fdroid.App { + var result []fdroid.App for _, app := range apps { if _, e := inst[app.PackageName]; !e { continue @@ -165,8 +165,8 @@ func filterAppsInstalled(apps []fdroidcl.App, inst map[string]adb.Package) []fdr return result } -func filterAppsUpdates(apps []fdroidcl.App, inst map[string]adb.Package, device *adb.Device) []fdroidcl.App { - var result []fdroidcl.App +func filterAppsUpdates(apps []fdroid.App, inst map[string]adb.Package, device *adb.Device) []fdroid.App { + var result []fdroid.App for _, app := range apps { p, e := inst[app.PackageName] if !e { @@ -184,8 +184,8 @@ func filterAppsUpdates(apps []fdroidcl.App, inst map[string]adb.Package, device return result } -func filterAppsLastUpdated(apps []fdroidcl.App, days int) []fdroidcl.App { - var result []fdroidcl.App +func filterAppsLastUpdated(apps []fdroid.App, days int) []fdroid.App { + var result []fdroid.App newer := true if days < 0 { days = -days @@ -210,8 +210,8 @@ func contains(l []string, s string) bool { return false } -func filterAppsCategory(apps []fdroidcl.App, categ string) []fdroidcl.App { - var result []fdroidcl.App +func filterAppsCategory(apps []fdroid.App, categ string) []fdroid.App { + var result []fdroid.App for _, app := range apps { if !contains(app.Categories, categ) { continue @@ -221,15 +221,15 @@ func filterAppsCategory(apps []fdroidcl.App, categ string) []fdroidcl.App { return result } -func cmpAdded(a, b *fdroidcl.App) bool { +func cmpAdded(a, b *fdroid.App) bool { return a.Added.Before(b.Added.Time) } -func cmpUpdated(a, b *fdroidcl.App) bool { +func cmpUpdated(a, b *fdroid.App) bool { return a.Updated.Before(b.Updated.Time) } -func sortFunc(sortBy string) (func(a, b *fdroidcl.App) bool, error) { +func sortFunc(sortBy string) (func(a, b *fdroid.App) bool, error) { switch sortBy { case "added": return cmpAdded, nil @@ -242,15 +242,15 @@ func sortFunc(sortBy string) (func(a, b *fdroidcl.App) bool, error) { } type appList struct { - l []fdroidcl.App - f func(a, b *fdroidcl.App) bool + l []fdroid.App + f func(a, b *fdroid.App) bool } func (al appList) Len() int { return len(al.l) } func (al appList) Swap(i, j int) { al.l[i], al.l[j] = al.l[j], al.l[i] } func (al appList) Less(i, j int) bool { return al.f(&al.l[i], &al.l[j]) } -func sortApps(apps []fdroidcl.App, f func(a, b *fdroidcl.App) bool) []fdroidcl.App { +func sortApps(apps []fdroid.App, f func(a, b *fdroid.App) bool) []fdroid.App { sort.Sort(appList{l: apps, f: f}) return apps } diff --git a/cmd/fdroidcl/show.go b/show.go similarity index 91% rename from cmd/fdroidcl/show.go rename to show.go index 8663ea7..ca89b8f 100644 --- a/cmd/fdroidcl/show.go +++ b/show.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "mvdan.cc/fdroidcl" + "mvdan.cc/fdroidcl/fdroid" ) var cmdShow = &Command{ @@ -37,8 +37,8 @@ func runShow(args []string) error { return nil } -func appsMap(apps []fdroidcl.App) map[string]*fdroidcl.App { - m := make(map[string]*fdroidcl.App, len(apps)) +func appsMap(apps []fdroid.App) map[string]*fdroid.App { + m := make(map[string]*fdroid.App, len(apps)) for i := range apps { app := &apps[i] m[app.PackageName] = app @@ -46,13 +46,13 @@ func appsMap(apps []fdroidcl.App) map[string]*fdroidcl.App { return m } -func findApps(ids []string) ([]*fdroidcl.App, error) { +func findApps(ids []string) ([]*fdroid.App, error) { apps, err := loadIndexes() if err != nil { return nil, err } byId := appsMap(apps) - result := make([]*fdroidcl.App, len(ids)) + result := make([]*fdroid.App, len(ids)) for i, id := range ids { var vcode = -1 j := strings.Index(id, ":") @@ -74,7 +74,7 @@ func findApps(ids []string) ([]*fdroidcl.App, error) { found := false for _, apk := range app.Apks { if apk.VersCode == vcode { - app.Apks = []*fdroidcl.Apk{apk} + app.Apks = []*fdroid.Apk{apk} found = true } } @@ -87,7 +87,7 @@ func findApps(ids []string) ([]*fdroidcl.App, error) { return result, nil } -func printAppDetailed(app fdroidcl.App) { +func printAppDetailed(app fdroid.App) { p := func(title string, format string, args ...interface{}) { if format == "" { fmt.Fprintln(stdout, title) diff --git a/cmd/fdroidcl/uninstall.go b/uninstall.go similarity index 100% rename from cmd/fdroidcl/uninstall.go rename to uninstall.go diff --git a/cmd/fdroidcl/update.go b/update.go similarity index 92% rename from cmd/fdroidcl/update.go rename to update.go index a1f62a8..d231ff4 100644 --- a/cmd/fdroidcl/update.go +++ b/update.go @@ -15,7 +15,7 @@ import ( "path/filepath" "sort" - "mvdan.cc/fdroidcl" + "mvdan.cc/fdroidcl/fdroid" ) var cmdUpdate = &Command{ @@ -54,7 +54,7 @@ func (r *repo) updateIndex() error { return downloadEtag(url, indexPath(r.ID), nil) } -func (r *repo) loadIndex() (*fdroidcl.Index, error) { +func (r *repo) loadIndex() (*fdroid.Index, error) { p := indexPath(r.ID) f, err := os.Open(p) if os.IsNotExist(err) { @@ -66,7 +66,7 @@ func (r *repo) loadIndex() (*fdroidcl.Index, error) { if err != nil { return nil, fmt.Errorf("could not stat index: %v", err) } - return fdroidcl.LoadIndexJar(f, stat.Size(), nil) + return fdroid.LoadIndexJar(f, stat.Size(), nil) } func respEtag(resp *http.Response) string { @@ -145,16 +145,16 @@ const cacheVersion = 2 type cache struct { Version int - Apps []fdroidcl.App + Apps []fdroid.App } -type apkPtrList []*fdroidcl.Apk +type apkPtrList []*fdroid.Apk func (al apkPtrList) Len() int { return len(al) } func (al apkPtrList) Swap(i, j int) { al[i], al[j] = al[j], al[i] } func (al apkPtrList) Less(i, j int) bool { return al[i].VersCode > al[j].VersCode } -func loadIndexes() ([]fdroidcl.App, error) { +func loadIndexes() ([]fdroid.App, error) { cachePath := filepath.Join(mustCache(), "cache-gob") if f, err := os.Open(cachePath); err == nil { defer f.Close() @@ -163,7 +163,7 @@ func loadIndexes() ([]fdroidcl.App, error) { return c.Apps, nil } } - m := make(map[string]*fdroidcl.App) + m := make(map[string]*fdroid.App) for _, r := range config.Repos { if !r.Enabled { continue @@ -187,11 +187,11 @@ func loadIndexes() ([]fdroidcl.App, error) { m[app.PackageName].Apks = apks } } - apps := make([]fdroidcl.App, 0, len(m)) + apps := make([]fdroid.App, 0, len(m)) for _, a := range m { apps = append(apps, *a) } - sort.Sort(fdroidcl.AppList(apps)) + sort.Sort(fdroid.AppList(apps)) if f, err := os.Create(cachePath); err == nil { defer f.Close() gob.NewEncoder(f).Encode(cache{