-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (63 loc) · 1.96 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
//android-sdk-mirror lets you create a local mirror of an android sdk repository.
//This can be very helpful in environments with restricted internet access.
package main
import (
"fmt"
"os"
log "github.com/Sirupsen/logrus"
"github.com/mandarl/go-selfupdate/selfupdate"
"github.com/mkideal/cli"
)
var VERSION string = "dev"
type argT struct {
cli.Helper
Url string `cli:"u,url" usage:"url of the repository you want to mirror"`
OutputDir string `cli:"*o,output-dir" usage:"output directory to save downloaded assets" dft:"."`
Version bool `cli:"!v,version" usage:"print the current version"`
Verbose bool `cli:"verbose" usage:"enable verbose logging"`
Silent bool `cli:"q,silent" usage:"suppresses any user input prompts"`
Serve bool `cli:"s,serve" usage:"simple built-in webserver serves files from the outputDir"`
Port int `cli:"p,serve-port" usage:"port to serve files" dft:"80"`
}
func main() {
cli.Run(&argT{}, func(ctx *cli.Context) error {
argv := ctx.Argv().(*argT)
run(argv)
return nil
})
}
func run(args *argT) {
if args.Version {
fmt.Printf("android-sdk-mirror: Verison: %s\n", VERSION)
os.Exit(0)
}
if args.Verbose {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.ErrorLevel)
}
runUpdate()
if args.Serve {
startWebServer(args.OutputDir, args.Port)
} else {
Process(args.Url, args.OutputDir, args.Silent)
}
}
func runUpdate() {
var updater = &selfupdate.Updater{
CurrentVersion: VERSION,
ApiURL: "http://dipoletech.com/projects/dist/",
//u.fetch(u.ApiURL + u.CmdName + "/" + plat + ".json")
BinURL: "http://dipoletech.com/projects/dist/",
//u.BinURL + u.CmdName + "/" + u.Info.Version
// + "/" + plat + ".gz"
DiffURL: "",
//u.fetch(u.DiffURL + u.CmdName + "/" + u.CurrentVersion
// + "/" + u.Info.Version + "/" + plat)
Dir: "update/",
CmdName: "android-sdk-mirror", // this is added to apiurl to get json
}
if updater != nil {
go updater.BackgroundRun()
}
}