-
Notifications
You must be signed in to change notification settings - Fork 6
/
command.go
92 lines (73 loc) · 1.88 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package apps
import (
"io"
"os"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
"github.com/giantswarm/kubectl-gs/pkg/middleware"
"github.com/giantswarm/kubectl-gs/pkg/middleware/renewtoken"
)
const (
name = "apps <app-name>"
alias = "app"
shortDescription = "Display one or many apps"
longDescription = `Display one or many apps
Output columns:
- NAME: Name of the app.
- VERSION: Version of the app.
- LAST DEPLOYED: When the app was last deployed.
- STATUS: Status of the app.`
examples = ` # List all apps for the current namespace
kubectl gs get apps
# Get one app by its name
kubectl gs get app coredns`
)
type Config struct {
Logger micrologger.Logger
FileSystem afero.Fs
K8sConfigAccess clientcmd.ConfigAccess
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.FileSystem == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.FileSystem must not be empty", config)
}
if config.K8sConfigAccess == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.K8sConfigAccess 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,
fs: config.FileSystem,
stderr: config.Stderr,
stdout: config.Stdout,
}
c := &cobra.Command{
Use: name,
Short: shortDescription,
Long: longDescription,
Example: examples,
Aliases: []string{alias},
Args: cobra.MaximumNArgs(1),
RunE: r.Run,
PreRunE: middleware.Compose(
renewtoken.Middleware(config.K8sConfigAccess),
),
}
f.Init(c)
return c, nil
}