-
Notifications
You must be signed in to change notification settings - Fork 6
/
command.go
90 lines (71 loc) · 2.01 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
package app
import (
"io"
"os"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"github.com/giantswarm/kubectl-gs/pkg/commonconfig"
"github.com/giantswarm/kubectl-gs/pkg/middleware"
"github.com/giantswarm/kubectl-gs/pkg/middleware/renewtoken"
)
const (
name = "app --name <app-name> --namespace <cluster-namespace> --version <updated-app-version>"
shortDescription = "Update App CR."
longDescription = `Update App CR.
Updates given app with the provided values.
Options:
--name <name> App CR name to update.
--namespace <cluster> Cluster to update the app on.
--version <version> New version to update the app to.`
examples = ` # Display this help
kubectl gs update app --help
# Update app version
kubectl gs update app --name hello-world-app --namespace ab01c --version 0.2.0`
)
type Config struct {
Logger micrologger.Logger
FileSystem afero.Fs
ConfigFlags *genericclioptions.RESTClientGetter
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.ConfigFlags == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.ConfigFlags 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{
commonConfig: &commonconfig.CommonConfig{
ConfigFlags: config.ConfigFlags,
},
flag: f,
logger: config.Logger,
stderr: config.Stderr,
stdout: config.Stdout,
}
c := &cobra.Command{
Use: name,
Short: shortDescription,
Long: longDescription,
Example: examples,
Args: cobra.MatchAll(cobra.ExactArgs(0), cobra.OnlyValidArgs),
RunE: r.Run,
PreRunE: middleware.Compose(
renewtoken.Middleware(*config.ConfigFlags),
),
}
f.Init(c)
return c, nil
}