-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
66 lines (49 loc) · 1.63 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
package main
import (
"github.com/jessevdk/go-flags"
"github.com/thecubed/docker-dupe/dupe"
"log"
"os"
"fmt"
)
const APP_NAME = "docker-dupe"
const APP_VERSION = "0.0.1"
var opts struct {
Debug bool `long:"debug" description:"Enable DEBUG logging"`
DoVersion bool `short:"V" long:"version" description:"Print version and exit"`
Source string `short:"s" long:"source" description:"Source docker registry URL" required:"true"`
Destination string `short:"d" long:"dest" description:"Destination docker registry URL" required:"true"`
ManifestName string `short:"n" long:"name" description:"Docker manifest name to pull from source" required:"true"`
ManifestTag string `short:"t" long:"tag" description:"Docker manifest tag to pull from source" required:"true"`
Concurrency int `short:"c" long:"concurrency" description:"Concurrent operation limit" default:"4"`
}
func main() {
// Parse arguments
_, err := flags.Parse(&opts)
// From https://www.snip2code.com/Snippet/605806/go-flags-suggested--h-documentation
if err != nil {
typ := err.(*flags.Error).Type
if typ == flags.ErrHelp {
os.Exit(0)
} else if !opts.DoVersion {
fmt.Println(err)
os.Exit(1)
}
}
// Print version number if requested from command line
if opts.DoVersion == true {
fmt.Printf("%s %s at your service.\n", APP_NAME, APP_VERSION)
os.Exit(10)
}
// Create the dupe agent
dupe := dupe.New(&dupe.DupeConfig{
UrlFrom: opts.Source,
UrlTo: opts.Destination,
Threads: opts.Concurrency,
Debug: opts.Debug,
})
// Copy the layers + manifest
dupe.Copy(opts.ManifestName, opts.ManifestTag)
// We done here. Go home
log.Print("Finished!!!")
}