-
Notifications
You must be signed in to change notification settings - Fork 2
/
command.go
53 lines (43 loc) · 892 Bytes
/
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
package bootstrap
import (
"io"
"os"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/spf13/cobra"
)
const (
name = "bootstrap"
description = "Bootstraps Giant Swarm app platform in an empty Kubernetes cluster."
)
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,
RunE: r.Run,
}
f.Init(c)
return c, nil
}