package main

import (
	"kode-starter/config"
	"kode-starter/create"
	"kode-starter/lists"
	"kode-starter/utils"
	"kode-starter/version"

	"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
	Use:   "kode-creator.exe",
	Short: "Simple cli app create startup project",
	Long:  `A simple CLI app to work with Github, Gitea`,
	Run: func(cmd *cobra.Command, args []string) {

		config.SetInformations(cmd, args)
		mainProgram(cmd, args)
	},
}

var token, org, name, private, description string
var verbose, createFlag bool

func init() {

	rootCmd.Flags().BoolP("help", "h", false, "Show help for create command")

	rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "mode verbose")
	rootCmd.PersistentFlags().BoolVarP(&createFlag, "json", "j", false, "Print output as json format")

	lists.ListCmd.Flags().StringVarP(&token, "token", "t", "", "Github token")
	lists.ListCmd.Flags().StringVarP(&org, "org", "o", "", "Github organization")

	create.CreateCmd.Flags().StringVarP(&token, "token", "t", "", "Github token")
	create.CreateCmd.Flags().StringVarP(&org, "org", "o", "", "Github organization")
	create.CreateCmd.Flags().StringVarP(&name, "name", "n", "", "Project name")
	create.CreateCmd.Flags().StringVarP(&description, "desc", "d", "", "Description")
	create.CreateCmd.Flags().StringVarP(&private, "private", "p", "", "true/false")

	rootCmd.AddCommand(lists.ListCmd)
	rootCmd.AddCommand(create.CreateCmd)

}

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

	config.SetInformations(cmd, args)

	utils.PrintHeader()

	// Check if the help flag is set
	if cmd.Flags().Changed("help") || cmd.Flags().Changed("h") {
		utils.PrintHelpFormated(version.GetFullVersion(), config.GetAuthor(), config.GetBuildDate(), cmd)
		return
	} else {
		// If no flag is set, show help
		utils.PrintHelpFormated(version.GetFullVersion(), config.GetAuthor(), config.GetBuildDate(), cmd)
		return
	}

}

func main() {

	rootCmd.Execute()

}
