package cmd

import (
	"os/exec"

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

// deployCmd represents the deploy command
var deployCmd = &cobra.Command{
	Use:   "deploy",
	Short: "Deploy the TiDB cluster",
	Long:  `Initialize the system environment and modify the kernel parameters.Deploy the TiDB cluster software which includes PD, TiDB, TiKV, Monitor(Prometheus/Pushgateway) and Dashboard UI.`,
	Run:   deploy,
}

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

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

	go progressBar(deployTaskCount)

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

	postTask()
}
