-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathshow.go
158 lines (147 loc) · 3.81 KB
/
show.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright (c) 2015, Daniel Martí <[email protected]>
// See LICENSE for licensing information
package main
import (
"fmt"
"os"
"strconv"
"strings"
"mvdan.cc/fdroidcl/fdroid"
)
var cmdShow = &Command{
UsageLine: "show <appid...>",
Short: "Show detailed info about apps",
}
func init() {
cmdShow.Run = runShow
}
func runShow(args []string) error {
if len(args) < 1 {
return fmt.Errorf("no package names given")
}
apps, err := findApps(args)
if err != nil {
return err
}
for i, app := range apps {
if i > 0 {
fmt.Printf("\n--\n\n")
}
printAppDetailed(app)
}
return nil
}
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
}
return m
}
func findApps(ids []string) ([]fdroid.App, error) {
apps, err := loadIndexes()
if err != nil {
return nil, err
}
byId := appsMap(apps)
result := make([]fdroid.App, len(ids))
for i, id := range ids {
vcode := -1
j := strings.Index(id, ":")
if j > -1 {
var err error
vcode, err = strconv.Atoi(id[j+1:])
if err != nil {
return nil, fmt.Errorf("could not parse version code from '%s'", id)
}
id = id[:j]
}
app, e := byId[id]
if !e {
return nil, fmt.Errorf("could not find app with ID '%s'", id)
}
if vcode > -1 {
found := false
for _, apk := range app.Apks {
if apk.VersCode == vcode {
app.Apks = []*fdroid.Apk{apk}
found = true
}
}
if !found {
return nil, fmt.Errorf("could not find version %d for app with ID '%s'", vcode, id)
}
}
result[i] = *app
}
return result, nil
}
func printAppDetailed(app fdroid.App) {
fmt.Printf("Package : %s\n", app.PackageName)
fmt.Printf("Name : %s\n", app.Name)
fmt.Printf("Summary : %s\n", app.Summary)
fmt.Printf("Added : %s\n", app.Added.String())
fmt.Printf("Last Updated : %s\n", app.Updated.String())
fmt.Printf("Version : %s (%d)\n", app.SugVersName, app.SugVersCode)
fmt.Printf("License : %s\n", app.License)
if app.Categories != nil {
fmt.Printf("Categories : %s\n", strings.Join(app.Categories, ", "))
}
if app.Website != "" {
fmt.Printf("Website : %s\n", app.Website)
}
if app.SourceCode != "" {
fmt.Printf("Source Code : %s\n", app.SourceCode)
}
if app.IssueTracker != "" {
fmt.Printf("Issue Tracker : %s\n", app.IssueTracker)
}
if app.Changelog != "" {
fmt.Printf("Changelog : %s\n", app.Changelog)
}
if app.Donate != "" {
fmt.Printf("Donate : %s\n", app.Donate)
}
if app.Bitcoin != "" {
fmt.Printf("Bitcoin : bitcoin:%s\n", app.Bitcoin)
}
if app.Litecoin != "" {
fmt.Printf("Litecoin : litecoin:%s\n", app.Litecoin)
}
if app.FlattrID != "" {
fmt.Printf("Flattr : https://flattr.com/thing/%s\n", app.FlattrID)
}
fmt.Printf("F-Droid Repository : %s (%s)\n", app.FdroidRepoName, app.FdroidRepoURL)
fmt.Println()
fmt.Println("Description :")
fmt.Println()
app.TextDesc(os.Stdout)
fmt.Println()
fmt.Println("Available Versions :")
for _, apk := range app.Apks {
fmt.Println()
fmt.Printf(" Version : %s (%d)\n", apk.VersName, apk.VersCode)
fmt.Printf(" Size : %d\n", apk.Size)
fmt.Printf(" MinSdk : %d\n", apk.MinSdk.Value)
if apk.MaxSdk.Value > 0 {
fmt.Printf(" MaxSdk : %d\n", apk.MaxSdk.Value)
}
if apk.ABIs != nil {
fmt.Printf(" ABIs : %s\n", strings.Join(apk.ABIs, ", "))
}
if apk.Perms != nil && len(apk.Perms) > 0 {
fmt.Printf(" Perms : ")
for i, value := range apk.Perms {
fmt.Print(value.Name)
if value.MaxSdk != "" {
fmt.Printf(" (MaxSdk %s)", value.MaxSdk)
}
if i != len(apk.Perms)-1 {
fmt.Print(", ")
}
}
fmt.Println()
}
}
}