mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
To keep both the Support Bundle and Preflight CLIs similar, this PR adds the ability for the Preflight binary to allow multiple specs be provided as CLI args and for them all to be run.
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/go-logr/logr"
|
|
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
|
|
"github.com/replicatedhq/troubleshoot/pkg/preflight"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"k8s.io/klog/v2"
|
|
)
|
|
|
|
func RootCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "preflight [url]",
|
|
Args: cobra.MinimumNArgs(1),
|
|
Short: "Run and retrieve preflight checks in a cluster",
|
|
Long: `A preflight check is a set of validations that can and should be run to ensure
|
|
that a cluster meets the requirements to run an application.`,
|
|
SilenceUsage: true,
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
v := viper.GetViper()
|
|
v.BindPFlags(cmd.Flags())
|
|
|
|
if !v.GetBool("debug") {
|
|
klog.SetLogger(logr.Discard())
|
|
}
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
v := viper.GetViper()
|
|
return preflight.RunPreflights(v.GetBool("interactive"), v.GetString("output"), v.GetString("format"), args)
|
|
},
|
|
}
|
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
cmd.AddCommand(VersionCmd())
|
|
preflight.AddFlags(cmd.PersistentFlags())
|
|
|
|
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
|
|
|
k8sutil.AddFlags(cmd.Flags())
|
|
|
|
return cmd
|
|
}
|
|
|
|
func InitAndExecute() {
|
|
if err := RootCmd().Execute(); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func initConfig() {
|
|
viper.SetEnvPrefix("PREFLIGHT")
|
|
viper.AutomaticEnv()
|
|
}
|