package schctl

import (
	"github.com/pingcap/schrodinger/cmd/sch-ctl/schctl/command"
	"github.com/spf13/cobra"
)

const (
	cliName        = "sch-ctl"
	cliDescription = "A simple command line client for schrodinger"
)

// CommandFlags are flags that used in all Commands
type CommandFlags struct {
	SchrodingerURL string
}

var (
	commandFlags = CommandFlags{}
)

var rootCmd = &cobra.Command{
	Use:        cliName,
	Short:      cliDescription,
	SuggestFor: []string{"sch-ctl"},
}

func init() {
	rootCmd.PersistentFlags().StringVar(&commandFlags.SchrodingerURL, "schrodinger", "http://172.16.30.12:60000", "schrodinger address")
	rootCmd.AddCommand(
		command.NewTestCommand(),
		command.NewConfigTemplateCommand(),
		command.NewBoxCommand(),
	)
}

// Execute execs Command
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		command.ExitWithError(command.ExitError, err)
	}
}
