-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
54 lines (43 loc) · 1.14 KB
/
root.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
package app
import (
"fmt"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"github.com/cfanbo/kubectr/internal/version"
)
func NewCmd() *cobra.Command {
o := newCtrOptions()
var rootCmd = &cobra.Command{
Use: "ctr podName", // This is prefixed by kubectl in the custom usage template
Short: "display all containers in the pod",
Long: `display all containers in the pod.
You can invoke ctr through kubectl: "kubectl ctr podName"`,
SilenceUsage: true,
SilenceErrors: true,
RunE: func(cmd *cobra.Command, args []string) error {
if ver, err := cmd.Flags().GetBool("version"); err != nil {
return err
} else if ver {
fmt.Println(version.FullVersion())
return nil
}
if len(args) == 0 {
_ = cmd.Help()
return nil
}
if err := o.Complete(cmd, args); err != nil {
return err
}
o.Run()
return nil
},
}
rootCmd.Flags().BoolVarP(&o.version, "version", "v", false, "Displays the current version number")
o.configFlags.AddFlags(rootCmd.Flags())
return rootCmd
}
func newCtrOptions() *CtrOptions {
return &CtrOptions{
configFlags: genericclioptions.NewConfigFlags(true),
}
}