forked from libopenstorage/stork
/
storkctl.go
50 lines (42 loc) · 1.24 KB
/
storkctl.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
package storkctl
import (
"flag"
"io"
"github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
)
// NewCommand Create a new storkctl command
func NewCommand(cmdFactory Factory, in io.Reader, out io.Writer, errOut io.Writer) *cobra.Command {
cmds := &cobra.Command{
Use: "storkctl",
Short: "storkctl manages stork resources",
PersistentPreRun: func(c *cobra.Command, args []string) {
err := cmdFactory.UpdateConfig()
if err != nil {
util.CheckErr(err)
return
}
},
}
ioStreams := genericclioptions.IOStreams{In: in, Out: out, ErrOut: errOut}
cmdFactory.BindFlags(cmds.PersistentFlags())
cmds.AddCommand(
newCreateCommand(cmdFactory, ioStreams),
newDeleteCommand(cmdFactory, ioStreams),
newGetCommand(cmdFactory, ioStreams),
newActivateCommand(cmdFactory, ioStreams),
newDeactivateCommand(cmdFactory, ioStreams),
newGenerateCommand(cmdFactory, ioStreams),
newSuspendCommand(cmdFactory, ioStreams),
newResumeCommand(cmdFactory, ioStreams),
newVersionCommand(cmdFactory, ioStreams),
)
cmds.PersistentFlags().AddGoFlagSet(flag.CommandLine)
err := flag.CommandLine.Parse([]string{})
if err != nil {
util.CheckErr(err)
return nil
}
return cmds
}