-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmd.go
54 lines (42 loc) · 1.5 KB
/
cmd.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 cmd
import (
"flag"
"fmt"
"os"
// Initialize all known client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/term"
"github.com/Ladicle/kubectl-diagnose/pkg/pritty"
)
var (
// set values via build flags
version string
commit string
)
func NewDiagnoseCmd() *cobra.Command {
cmds := &cobra.Command{
Use: "diagnose",
Version: fmt.Sprintf("%v @%v", version, commit),
DisableFlagsInUseLine: true,
Short: "Diagnose Kubernetes resource status",
Run: cmdutil.DefaultSubCommandRun(os.Stderr),
}
flags := cmds.PersistentFlags()
flags.AddGoFlagSet(flag.CommandLine)
kubeConfigFlags := genericclioptions.NewConfigFlags(true)
kubeConfigFlags.AddFlags(flags)
matchVersionFlags := cmdutil.NewMatchVersionFlags(kubeConfigFlags)
matchVersionFlags.AddFlags(flags)
f := cmdutil.NewFactory(matchVersionFlags)
ioStreams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
printer := &pritty.Printer{IOStreams: ioStreams}
cmds.PersistentFlags().BoolVarP(&printer.Color, "color", "R", false, "Enable color output even if stdout is not a terminal")
printer.TTY = term.TTY{Out: ioStreams.Out}.IsTerminalOut()
cmds.AddCommand(NewDeploymentCmd(f, printer))
cmds.AddCommand(NewStatefulSetCmd(f, printer))
cmds.AddCommand(NewDaemonSetCmd(f, printer))
return cmds
}