diff --git a/cmd/fdroidcl/main.go b/cmd/fdroidcl/main.go index b013fee..954b9cc 100644 --- a/cmd/fdroidcl/main.go +++ b/cmd/fdroidcl/main.go @@ -90,6 +90,67 @@ func printApps(apps map[string]fdroidcl.App) { } } +func printAppDetailed(app fdroidcl.App) { + p := func(title string, format string, args ...interface{}) { + if format == "" { + fmt.Println(title) + } else { + fmt.Printf("%s %s\n", title, fmt.Sprintf(format, args...)) + } + } + p("Name :", "%s", app.Name) + p("Summary :", "%s", app.Summary) + p("Current Version :", "%s (%d)", app.CurApk.VName, app.CurApk.VCode) + p("Upstream Version :", "%s (%d)", app.CVName, app.CVCode) + p("License :", "%s", app.License) + if app.Categs != nil { + p("Categories :", "%s", strings.Join(app.Categs, ", ")) + } + if app.Website != "" { + p("Website :", "%s", app.Website) + } + if app.Source != "" { + p("Source :", "%s", app.Source) + } + if app.Tracker != "" { + p("Tracker :", "%s", app.Tracker) + } + if app.Donate != "" { + p("Donate :", "%s", app.Donate) + } + if app.Bitcoin != "" { + p("Bitcoin :", "bitcoin:%s", app.Bitcoin) + } + if app.Litecoin != "" { + p("Litecoin :", "litecoin:%s", app.Litecoin) + } + if app.Dogecoin != "" { + p("Dogecoin :", "dogecoin:%s", app.Dogecoin) + } + if app.FlattrID != "" { + p("Flattr :", "https://flattr.com/thing/%s", app.FlattrID) + } + fmt.Println() + p("Description :", "") + fmt.Println() + app.TextDesc(os.Stdout) + fmt.Println() + p("Available Versions :", "") + for _, apk := range app.Apks { + fmt.Println() + p(" Name :", "%s (%d)", apk.VName, apk.VCode) + p(" Size :", "%d", apk.Size) + p(" MinSdk :", "%d", apk.MinSdk) + if apk.MaxSdk > 0 { + p(" MaxSdk :", "%d", apk.MaxSdk) + } + if apk.ABIs != nil { + p(" ABIs :", "%s", strings.Join(apk.ABIs, ", ")) + } + } +} + + var repoURL = flag.String("r", "https://f-droid.org/repo", "repository address") func init() { @@ -169,7 +230,7 @@ func main() { if !e { log.Fatalf("Could not find app with ID '%s'", appID) } - app.WriteDetailed(os.Stdout) + printAppDetailed(app) } case "devices": devices, err := adb.Devices() diff --git a/index.go b/index.go index 2bfb116..1bb156b 100644 --- a/index.go +++ b/index.go @@ -73,7 +73,7 @@ func (app *App) calcCurApk() { } } -func (app *App) writeTextDesc(w io.Writer) { +func (app *App) TextDesc(w io.Writer) { reader := strings.NewReader(app.Desc) decoder := xml.NewDecoder(reader) firstParagraph := true @@ -168,66 +168,6 @@ func (app *App) prepareData() { app.calcCurApk() } -func (app *App) WriteDetailed(w io.Writer) { - p := func(title string, format string, args ...interface{}) { - if format == "" { - fmt.Fprintln(w, title) - } else { - fmt.Fprintf(w, "%s %s\n", title, fmt.Sprintf(format, args...)) - } - } - p("Name :", "%s", app.Name) - p("Summary :", "%s", app.Summary) - p("Current Version :", "%s (%d)", app.CurApk.VName, app.CurApk.VCode) - p("Upstream Version :", "%s (%d)", app.CVName, app.CVCode) - p("License :", "%s", app.License) - if app.Categs != nil { - p("Categories :", "%s", strings.Join(app.Categs, ", ")) - } - if app.Website != "" { - p("Website :", "%s", app.Website) - } - if app.Source != "" { - p("Source :", "%s", app.Source) - } - if app.Tracker != "" { - p("Tracker :", "%s", app.Tracker) - } - if app.Donate != "" { - p("Donate :", "%s", app.Donate) - } - if app.Bitcoin != "" { - p("Bitcoin :", "bitcoin:%s", app.Bitcoin) - } - if app.Litecoin != "" { - p("Litecoin :", "litecoin:%s", app.Litecoin) - } - if app.Dogecoin != "" { - p("Dogecoin :", "dogecoin:%s", app.Dogecoin) - } - if app.FlattrID != "" { - p("Flattr :", "https://flattr.com/thing/%s", app.FlattrID) - } - fmt.Println() - p("Description :", "") - fmt.Println() - app.writeTextDesc(w) - fmt.Println() - p("Available Versions :", "") - for _, apk := range app.Apks { - fmt.Println() - p(" Name :", "%s (%d)", apk.VName, apk.VCode) - p(" Size :", "%d", apk.Size) - p(" MinSdk :", "%d", apk.MinSdk) - if apk.MaxSdk > 0 { - p(" MaxSdk :", "%d", apk.MaxSdk) - } - if apk.ABIs != nil { - p(" ABIs :", "%s", strings.Join(apk.ABIs, ", ")) - } - } -} - var ErrNotModified = errors.New("etag matches, file was not modified") func downloadEtag(url, path string) error {