package main

import (
	"flag"
	"fmt"
	"kube-forge/internal/config"
	"kube-forge/internal/kubespray"
	"kube-forge/internal/templates"
	"os"
)

func main() {
	var password, configPath, workDir string
	var verbose bool

	flag.StringVar(&password, "p", "", "Password to access hosts")
	flag.StringVar(&configPath, "c", "/etc/kube-forge/config.yaml", "Path to config file")
	flag.StringVar(&workDir, "d", "/var/lib/kube-forge", "Path to kube-forge work dir")
	flag.BoolVar(&verbose, "v", false, "Enable verbose logging")
	flag.Parse()
	config := config.CreateConfig(configPath, workDir, password)
	config.Verbose = verbose
	repositories, releases := templates.GetHelmAppsConfigData()
	config.Repositories = repositories
	config.Releases = releases

	templates.ApplyK8sTemplates()

	for _, cmd := range os.Args {
		switch cmd {
		case "apply":
			kubespray.InstallCluster("")
			return
		case "apply-modules":
			kubespray.InstallCluster("helm-apps")
			return
		case "upgrade":
			kubespray.UpgradeCluster("")
			return
		case "scale":
			kubespray.ScaleCluster()
			return
		}
	}
	fmt.Println("No such command\nAvailable commands: apply, apply-modules, upgrade, scale")
}
