-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepo.go
96 lines (87 loc) · 1.98 KB
/
repo.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 (
"fmt"
"github.com/codegangsta/cli"
"os"
)
func main() {
app := cli.NewApp()
app.Name = "repo"
app.Usage = "to deal with maven repositories"
app.Version = "0.1.0"
app.Commands = []cli.Command{
{
Name: "pull",
ShortName: "d",
Flags: []cli.Flag{
cli.StringFlag{
Name: "destination,d",
Usage: "Defines download destination.",
EnvVar: "MVN_DEST",
Value: ".",
},
cli.StringFlag{
Name: "baseUrl,b",
Usage: "Defines maven base repo url",
EnvVar: "MVN_BASE_URL",
Value: "http://central.maven.org/maven2",
},
cli.StringFlag{
Name: "template,t",
Usage: "Defines file template",
EnvVar: "MVN_FILE_TMPL",
Value: "{{.Id}}-{{.Version}}.{{.Ext}}",
},
cli.BoolFlag{
Name: "verbose,v",
Usage: "verbose output.",
},
cli.BoolFlag{
Name: "recursive,r",
Usage: "Recursive download of pom dependencies",
},
cli.StringFlag{
Name: "extension,e",
Usage: "Default extension",
Value: "jar",
},
},
Usage: "Downloads artifact from maven repository.",
Action: DownloadCommand,
},
}
app.Run(os.Args)
}
func prepareArtifact(c *cli.Context) []Artifact {
artifacts := make([]Artifact, 0)
for _, el := range c.Args() {
artifact, err := ParseArtifact(el, c.String("e"))
checkError(err)
artifacts = append(artifacts, artifact)
}
return artifacts
}
func DownloadCommand(c *cli.Context) {
if c.Bool("verbose") {
fmt.Println("[INFO] Destination: " + c.String("d"))
fmt.Println("[INFO] Template: " + c.String("t"))
fmt.Println("[INFO] Base URL: " + c.String("b"))
}
if len(c.Args()) > 0 {
conf := Config{
c.String("b"),
c.String("d"),
c.String("t"),
false,
5,
c.Bool("r"),
}
tracker := NewTracker(conf)
for _, a := range prepareArtifact(c) {
tracker.Request(a)
}
checkError(tracker.Wait())
} else if c.Bool("verbose") {
fmt.Println("[INFO] No artifacts defined. Nothing to do." )
}
}