-
Notifications
You must be signed in to change notification settings - Fork 7
/
command.go
63 lines (50 loc) · 1.44 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
62
63
package catalog
import (
"io"
"os"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/spf13/cobra"
)
const (
name = "catalog"
description = "Template Catalog CR."
example = `
Basic catalog with a single repository:
kubectl-gs template catalog --name my-catalog --target-namespace default --logo https://example.com/img.jpg --description 'Custom catalog' --type helm --url https://example.com/helm-catalog/
Catalog with a multiple repository mirrors:
kubectl-gs template catalog --name my-catalog --target-namespace default --logo https://example.com/img.jpg --description 'Custom catalog' --type helm --url https://example.com/helm-catalog/ --type helm --url https://example.com/helm-mirror/ --type oci --url oci://example.com/oci-registry/
`
)
type Config struct {
Logger micrologger.Logger
Stderr io.Writer
Stdout io.Writer
}
func New(config Config) (*cobra.Command, error) {
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
if config.Stderr == nil {
config.Stderr = os.Stderr
}
if config.Stdout == nil {
config.Stdout = os.Stdout
}
f := &flag{}
r := &runner{
flag: f,
logger: config.Logger,
stderr: config.Stderr,
stdout: config.Stdout,
}
c := &cobra.Command{
Use: name,
Short: description,
Long: description,
Example: example,
RunE: r.Run,
}
f.Init(c)
return c, nil
}