package cmd

import (
	"os/exec"

	log "github.com/sirupsen/logrus"
	"github.com/spf13/cobra"
)

// startCmd represents the start command
var startCmd = &cobra.Command{
	Use:   "start",
	Short: "Start the TiDB cluster",
	Long:  `Start the services of TiDB cluster which includes PD, TiDB, TiKV, Monitor(Prometheus/Pushgateway) and Dashboard UI.`,
	Run:   start,
}

func init() {
	rootCmd.AddCommand(startCmd)
}

func start(cmd *cobra.Command, args []string) {
	preTask()

	go progressBar(startTaskCount)

	command := exec.Command("sh", "-c", "ansible-playbook start.yml")
	err := command.Run()
	if err != nil {
		printFailedLog()
		log.Fatalln("failed to start the TiDB cluster.")
	}

	postTask()
}
