-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (51 loc) · 1.29 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
package main
import (
"fmt"
"os"
"strings"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var (
pluginVersion = "unknown"
)
func main() {
// TODO Add the env file functionality
app := cli.NewApp()
app.Name = "artifact metadata publisher plugin"
app.Usage = "artifact metadata publisher plugin"
app.Action = run
app.Version = pluginVersion
app.Flags = []cli.Flag{
cli.StringSliceFlag{
Name: "urls",
Usage: "URL of files to publish as artifact",
EnvVar: "PLUGIN_FILE_URLS",
},
cli.StringFlag{
Name: "artifact-file",
Usage: "Artifact file location that will be generated by the plugin. This file will include information of docker images that are uploaded by the plugin.",
EnvVar: "PLUGIN_ARTIFACT_FILE",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(c *cli.Context) error {
urls := c.StringSlice("urls")
artifactFilePath := c.String("artifact-file")
files := make([]File, 0)
for i, url := range urls {
parts := strings.Split(url, ":::")
if len(parts) != 2 {
files = append(files, File{Name: fmt.Sprintf("file-%d", i), URL: url})
continue
}
name := parts[0]
url := parts[1]
// Append to files slice
files = append(files, File{Name: name, URL: url})
}
return writeArtifactFile(files, artifactFilePath)
}