-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
61 lines (55 loc) · 2.3 KB
/
command.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
package main
import (
"github.com/spf13/cobra"
"github.com/tliron/commonlog"
cobrautil "github.com/tliron/kutil/cobra"
"github.com/tliron/kutil/terminal"
"github.com/tliron/kutil/util"
)
var logTo string
var verbose int
var colorize string
var directoryPath string
var registry string
var certificatePath string
var username string
var password string
var token string
var queue int
var healthPort uint
func init() {
command.PersistentFlags().StringVarP(&logTo, "log", "l", "", "log to file (defaults to stderr)")
command.PersistentFlags().CountVarP(&verbose, "verbose", "v", "add a log verbosity level (can be used twice)")
command.PersistentFlags().StringVarP(&colorize, "colorize", "z", "true", "colorize output (boolean or \"force\")")
command.PersistentFlags().StringVarP(&directoryPath, "directory", "d", "/spool", "spool directory path")
command.PersistentFlags().StringVarP(®istry, "registry", "r", "localhost:5000", "registry URL")
command.PersistentFlags().StringVarP(&certificatePath, "certificate", "c", "", "registry TLS certificate file path (in PEM format)")
command.PersistentFlags().StringVarP(&username, "username", "u", "", "registry authentication username")
command.PersistentFlags().StringVarP(&password, "password", "p", "", "registry authentication password")
command.PersistentFlags().StringVarP(&token, "token", "t", "", "registry authentication token")
command.PersistentFlags().IntVarP(&queue, "queue", "q", 10, "maximum number of files to queue at once")
command.PersistentFlags().UintVar(&healthPort, "health-port", 8086, "HTTP port for health check (for liveness and readiness probes)")
cobrautil.SetFlagsFromEnvironment("REPOSURE_REGISTRY_SPOOLER_", command)
}
var command = &cobra.Command{
Use: "reposure-registry-spooler",
Short: "Spooler for a container image registry",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
cleanup, err := terminal.ProcessColorizeFlag(colorize)
util.FailOnError(err)
if cleanup != nil {
util.OnExitError(cleanup)
}
if logTo == "" {
commonlog.Configure(verbose, nil)
} else {
commonlog.Configure(verbose, &logTo)
}
},
Run: func(cmd *cobra.Command, args []string) {
if (directoryPath == "") || (registry == "") {
util.Fail("must provide \"--directory\" and \"--registry\"")
}
RunSpooler(registry, directoryPath)
},
}