This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
89 lines (84 loc) · 1.86 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
package main
import (
"fmt"
"os"
"strings"
kingpin "gopkg.in/alecthomas/kingpin.v2"
artifactory "github.com/lusis/go-artifactory/artifactory.v54"
"github.com/lusis/outputter"
)
var (
format = kingpin.Flag("format", "format to display output").
Default("table").
Enum(outputter.GetOutputters()...)
groupid = kingpin.Flag("groupid", "groupid coordinate").String()
artifactid = kingpin.Flag("artifactid", "artifactid coordinate").String()
version = kingpin.Flag("version", "version coordinate").String()
classifier = kingpin.Flag("classifier", "classifier coordinate").String()
repo = kingpin.Flag("repo", "repo to search against. can be specified multiple times").Strings()
)
func main() {
kingpin.Parse()
output, _ := outputter.NewOutputter(*format)
client, clientErr := artifactory.NewClientFromEnv()
if clientErr != nil {
fmt.Printf("%s\n", clientErr.Error())
os.Exit(1)
}
var coords artifactory.GAVC
if groupid != nil {
coords.GroupID = *groupid
}
if artifactid != nil {
coords.ArtifactID = *artifactid
}
if version != nil {
coords.Version = *version
}
if classifier != nil {
coords.Classifier = *classifier
}
if repo != nil {
coords.Repos = *repo
}
data, err := client.GAVCSearch(&coords)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
output.SetHeaders([]string{
"File",
"Repo",
"RemoteUrl",
"Created",
"Last Modified",
"Created By",
"Modified By",
"SHA1",
"MD5",
"Size",
"MimeType",
"Download",
})
for _, r := range data {
elems := strings.Split(r.Path, "/")
fileName := elems[len(elems)-1]
_ = output.AddRow([]string{
fileName,
r.Repo,
r.RemoteURL,
r.Created,
r.LastModified,
r.CreatedBy,
r.ModifiedBy,
r.Checksums.SHA1,
r.Checksums.MD5,
r.Size,
r.MimeType,
r.DownloadURI,
})
}
output.Draw()
os.Exit(0)
}
}