This commit is contained in:
up9-github
2021-04-21 15:21:12 +03:00
parent 7167923a49
commit 4afd3ec9ac
5 changed files with 143 additions and 100 deletions

View File

@@ -7,7 +7,18 @@ import (
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{}
var (
rootCmd = &cobra.Command{}
// TODO: bundle these up into a single config object, consider using viper for this
DisplayVersion bool
Quiet bool
NoDashboard bool
DashboardPort uint16
Namespace string
AllNamespaces bool
KubeConfigPath string
)
func init() {
rootCmd.Use = "cmd pod-query"
rootCmd.Short = "Tail HTTP traffic from multiple pods"
@@ -15,10 +26,19 @@ func init() {
if len(args) != 1 {
return rootCmd.Help()
}
regex := regexp.MustCompile(args[0]) // MustCompile panics if expression cant be compiled into regex
mizu.Run(regex)
return nil
}
rootCmd.Flags().BoolVarP(&DisplayVersion, "version", "v", false, "Print the version and exit")
rootCmd.Flags().BoolVarP(&Quiet, "quiet", "q", false, "No stdout output")
rootCmd.Flags().BoolVarP(&NoDashboard, "no-dashboard", "", false, "Dont host a dashboard")
rootCmd.Flags().Uint16VarP(&DashboardPort, "dashboard-port", "p", 3000, "Provide a custom port for the dashboard webserver")
rootCmd.Flags().StringVarP(&Namespace, "namespace", "n", "", "Namespace selector")
rootCmd.Flags().BoolVarP(&AllNamespaces, "all-namespaces", "A", false, "Select all namespaces")
rootCmd.Flags().StringVarP(&KubeConfigPath, "kubeconfig", "k", "", "Path to kubeconfig file")
}
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -26,13 +46,3 @@ func init() {
func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
func init() {
rootCmd.Flags().BoolP("version", "v", false, "Print the version and exit")
rootCmd.Flags().BoolP("quiet", "q", false, "No stdout output")
rootCmd.Flags().BoolP("no-dashboard", "", false, "Dont host a dashboard")
rootCmd.Flags().Uint16P("dashboard-port", "p", 3000, "Provide a custom port for the dashboard webserver")
rootCmd.Flags().StringP("namespace", "n", "", "Namespace selector")
rootCmd.Flags().BoolP("all-namespaces", "A", false, "Select all namespaces")
rootCmd.Flags().StringP("kubeconfig", "k", "", "Path to kubeconfig file")
}