mirror of https://github.com/mvdan/fdroidcl.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
3.5 KiB
154 lines
3.5 KiB
|
11 years ago
|
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
||
|
|
// See LICENSE for licensing information
|
||
|
11 years ago
|
|
||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
10 years ago
|
"strconv"
|
||
|
11 years ago
|
"strings"
|
||
|
|
|
||
|
7 years ago
|
"mvdan.cc/fdroidcl/fdroid"
|
||
|
11 years ago
|
)
|
||
|
|
|
||
|
|
var cmdShow = &Command{
|
||
|
11 years ago
|
UsageLine: "show <appid...>",
|
||
|
11 years ago
|
Short: "Show detailed info about an app",
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
|
func init() {
|
||
|
|
cmdShow.Run = runShow
|
||
|
|
}
|
||
|
|
|
||
|
9 years ago
|
func runShow(args []string) error {
|
||
|
11 years ago
|
if len(args) < 1 {
|
||
|
9 years ago
|
return fmt.Errorf("no package names given")
|
||
|
|
}
|
||
|
|
apps, err := findApps(args)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
11 years ago
|
}
|
||
|
11 years ago
|
for i, app := range apps {
|
||
|
|
if i > 0 {
|
||
|
8 years ago
|
fmt.Fprintf(stdout, "\n--\n\n")
|
||
|
11 years ago
|
}
|
||
|
|
printAppDetailed(*app)
|
||
|
|
}
|
||
|
9 years ago
|
return nil
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
7 years ago
|
func appsMap(apps []fdroid.App) map[string]*fdroid.App {
|
||
|
|
m := make(map[string]*fdroid.App, len(apps))
|
||
|
11 years ago
|
for i := range apps {
|
||
|
|
app := &apps[i]
|
||
|
8 years ago
|
m[app.PackageName] = app
|
||
|
11 years ago
|
}
|
||
|
|
return m
|
||
|
|
}
|
||
|
|
|
||
|
7 years ago
|
func findApps(ids []string) ([]*fdroid.App, error) {
|
||
|
9 years ago
|
apps, err := loadIndexes()
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
byId := appsMap(apps)
|
||
|
7 years ago
|
result := make([]*fdroid.App, len(ids))
|
||
|
11 years ago
|
for i, id := range ids {
|
||
|
10 years ago
|
var vcode = -1
|
||
|
|
j := strings.Index(id, ":")
|
||
|
|
if j > -1 {
|
||
|
|
var err error
|
||
|
|
vcode, err = strconv.Atoi(id[j+1:])
|
||
|
|
if err != nil {
|
||
|
9 years ago
|
return nil, fmt.Errorf("could not parse version code from '%s'", id)
|
||
|
10 years ago
|
}
|
||
|
|
id = id[:j]
|
||
|
|
}
|
||
|
|
|
||
|
9 years ago
|
app, e := byId[id]
|
||
|
11 years ago
|
if !e {
|
||
|
9 years ago
|
return nil, fmt.Errorf("could not find app with ID '%s'", id)
|
||
|
11 years ago
|
}
|
||
|
10 years ago
|
|
||
|
|
if vcode > -1 {
|
||
|
|
found := false
|
||
|
|
for _, apk := range app.Apks {
|
||
|
8 years ago
|
if apk.VersCode == vcode {
|
||
|
7 years ago
|
app.Apks = []*fdroid.Apk{apk}
|
||
|
10 years ago
|
found = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if !found {
|
||
|
9 years ago
|
return nil, fmt.Errorf("could not find version %d for app with ID '%s'", vcode, id)
|
||
|
10 years ago
|
}
|
||
|
|
}
|
||
|
11 years ago
|
result[i] = app
|
||
|
11 years ago
|
}
|
||
|
9 years ago
|
return result, nil
|
||
|
11 years ago
|
}
|
||
|
|
|
||
|
7 years ago
|
func printAppDetailed(app fdroid.App) {
|
||
|
11 years ago
|
p := func(title string, format string, args ...interface{}) {
|
||
|
|
if format == "" {
|
||
|
8 years ago
|
fmt.Fprintln(stdout, title)
|
||
|
11 years ago
|
} else {
|
||
|
8 years ago
|
fmt.Fprintf(stdout, "%s %s\n", title, fmt.Sprintf(format, args...))
|
||
|
11 years ago
|
}
|
||
|
|
}
|
||
|
8 years ago
|
p("Package :", "%s", app.PackageName)
|
||
|
11 years ago
|
p("Name :", "%s", app.Name)
|
||
|
|
p("Summary :", "%s", app.Summary)
|
||
|
11 years ago
|
p("Added :", "%s", app.Added.String())
|
||
|
|
p("Last Updated :", "%s", app.Updated.String())
|
||
|
8 years ago
|
p("Version :", "%s (%d)", app.SugVersName, app.SugVersCode)
|
||
|
11 years ago
|
p("License :", "%s", app.License)
|
||
|
8 years ago
|
if app.Categories != nil {
|
||
|
|
p("Categories :", "%s", strings.Join(app.Categories, ", "))
|
||
|
11 years ago
|
}
|
||
|
|
if app.Website != "" {
|
||
|
|
p("Website :", "%s", app.Website)
|
||
|
|
}
|
||
|
8 years ago
|
if app.SourceCode != "" {
|
||
|
|
p("Source Code :", "%s", app.SourceCode)
|
||
|
11 years ago
|
}
|
||
|
8 years ago
|
if app.IssueTracker != "" {
|
||
|
|
p("Issue Tracker :", "%s", app.IssueTracker)
|
||
|
11 years ago
|
}
|
||
|
|
if app.Changelog != "" {
|
||
|
|
p("Changelog :", "%s", app.Changelog)
|
||
|
|
}
|
||
|
|
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.FlattrID != "" {
|
||
|
|
p("Flattr :", "https://flattr.com/thing/%s", app.FlattrID)
|
||
|
|
}
|
||
|
8 years ago
|
fmt.Fprintln(stdout)
|
||
|
11 years ago
|
p("Description :", "")
|
||
|
8 years ago
|
fmt.Fprintln(stdout)
|
||
|
|
app.TextDesc(stdout)
|
||
|
|
fmt.Fprintln(stdout)
|
||
|
11 years ago
|
p("Available Versions :", "")
|
||
|
|
for _, apk := range app.Apks {
|
||
|
8 years ago
|
fmt.Fprintln(stdout)
|
||
|
8 years ago
|
p(" Version :", "%s (%d)", apk.VersName, apk.VersCode)
|
||
|
10 years ago
|
p(" Size :", "%d", apk.Size)
|
||
|
|
p(" MinSdk :", "%d", apk.MinSdk)
|
||
|
11 years ago
|
if apk.MaxSdk > 0 {
|
||
|
10 years ago
|
p(" MaxSdk :", "%d", apk.MaxSdk)
|
||
|
11 years ago
|
}
|
||
|
|
if apk.ABIs != nil {
|
||
|
10 years ago
|
p(" ABIs :", "%s", strings.Join(apk.ABIs, ", "))
|
||
|
11 years ago
|
}
|
||
|
10 years ago
|
if apk.Perms != nil {
|
||
|
10 years ago
|
p(" Perms :", "%s", strings.Join(apk.Perms, ", "))
|
||
|
10 years ago
|
}
|
||
|
11 years ago
|
}
|
||
|
|
}
|