package cmd

import (
	"github.com/spf13/cobra"
)

var (
	debug             bool
	storeType         string
	agentAddress      string
	instanceID        string
	instanceName      string
	instanceComp      string
	clusterIDStr      string
	tlsCAPath         string
	tlsCertPath       string
	tlsKeyPath        string
	reconcileInterval uint
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
	Use:   "topsqlagent",
	Short: "TiDB Top SQL agent program",
	Long:  `This program contains supervisor and the agent.`,
	// Uncomment the following line if your bare application
	// has an action associated with it:
	// Run: func(cmd *cobra.Command, args []string) { },
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
	cobra.CheckErr(rootCmd.Execute())
}

func init() {
	rootCmd.PersistentFlags().BoolVar(&debug, "debug", true, "enable debug logging level")
	rootCmd.PersistentFlags().StringVar(&storeType, "store", "tidb", "select the store implementation, defaults to tidb")
	rootCmd.PersistentFlags().StringVar(&agentAddress, "agent-address", ":10000", "specify the gRPC server listening address")
	rootCmd.PersistentFlags().StringVar(&metricsAddress, "metrics-address", ":10001", "specify the prometheus metrics address")
	rootCmd.PersistentFlags().StringVar(&instanceID, "instance-id", "", "set the instance ID of the tidb-server/tikv-server reporting to this agent")
	rootCmd.PersistentFlags().StringVar(&instanceName, "instance-name", "", "set the instance name of the tidb-server/tikv-server reporting to this agent")
	rootCmd.PersistentFlags().StringVar(&instanceComp, "instance-component", "", "set the instance component of the tidb-server/tikv-server reporting to this agent, like tidb|tikv")
	rootCmd.PersistentFlags().StringVar(&clusterIDStr, "cluster-id", "", "set the tidb cluster ID of the tidb-server/tikv-server reporting to this agent")
	rootCmd.PersistentFlags().StringVar(&tlsCAPath, "tls-ca", "", "set the CA file for TLS connection")
	rootCmd.PersistentFlags().StringVar(&tlsCertPath, "tls-cert", "", "set the client cert file for TLS connection")
	rootCmd.PersistentFlags().StringVar(&tlsKeyPath, "tls-key", "", "set the client key file for TLS connection")
	rootCmd.PersistentFlags().UintVar(&reconcileInterval, "reconcile-interval", 60, "set the reconcile interval of topsql agent process in seconds")
}
