generated from moul/golang-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
96 lines (86 loc) · 1.82 KB
/
main.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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"github.com/peterbourgon/ff/v3/ffcli"
"moul.io/pkgman/pkg/apk"
"moul.io/pkgman/pkg/ipa"
"moul.io/u"
)
func main() {
if err := run(os.Args); err != nil {
log.Fatalf("error: %v", err)
os.Exit(1)
}
}
func run(args []string) error {
root := &ffcli.Command{
ShortUsage: `pkgman SUBCOMMAND`,
Subcommands: []*ffcli.Command{
{Name: "ipa-plist-json", ShortUsage: "ipa-plist-json PATH", Exec: runIpaPlistJSON},
{Name: "apk-manifest", ShortUsage: "apk-manifest PATH", Exec: runApkManifest},
{Name: "apk-manifest-xml", ShortUsage: "apk-manifest-xml PATH", Exec: runApkManifestXML},
},
Exec: func(context.Context, []string) error { return flag.ErrHelp },
}
return root.ParseAndRun(context.Background(), args[1:])
}
func runIpaPlistJSON(_ context.Context, args []string) error {
if len(args) < 1 {
return flag.ErrHelp
}
for _, arg := range args {
pkg, err := ipa.Open(arg)
if err != nil {
return err
}
defer pkg.Close()
for _, app := range pkg.Apps() {
plist, err := app.Plist()
if err != nil {
return err
}
fmt.Println(u.PrettyJSON(plist))
}
}
return nil
}
func runApkManifest(_ context.Context, args []string) error {
if len(args) < 1 {
return flag.ErrHelp
}
for _, arg := range args {
pkg, err := apk.Open(arg)
if err != nil {
return err
}
defer pkg.Close()
manifest, err := pkg.Manifest()
if err != nil {
return err
}
fmt.Println(u.PrettyJSON(manifest))
}
return nil
}
func runApkManifestXML(_ context.Context, args []string) error {
if len(args) < 1 {
return flag.ErrHelp
}
for _, arg := range args {
pkg, err := apk.Open(arg)
if err != nil {
return err
}
defer pkg.Close()
manifest, err := pkg.ManifestXML()
if err != nil {
return err
}
fmt.Println(manifest)
}
return nil
}