package main import ( "kode-creator/cmdCreate" "kode-creator/cmdEnv" "kode-creator/cmdLists" "kode-creator/config" "kode-creator/utils" "kode-creator/version" "github.com/spf13/cobra" ) // initailize global config var CfgGlobal = &config.Config{} // rootCmd represents the base command when called without any subcommands 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) { mainProgram(cmd, args) }, } // init function that will be executed before the main function func init() { CfgGlobal.Init() // root menu section rootCmd.Flags().BoolP("help", "h", false, "Show help for "+CfgGlobal.GetApplicationName()) rootCmd.Flags().BoolVarP(&CfgGlobal.VersionFlag, "version", "V", false, "Show VERSION of "+CfgGlobal.GetApplicationName()) rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.VerboseFlag, "verbose", "v", false, "VERBOSE mode output") rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.JsonFlag, "json", "j", false, "JSON output format") // List menu section cmdLists.ListCmd.Flags().StringVarP(&CfgGlobal.TokenEnv, "token", "t", "", "TOKEN for Gitea or Github") cmdLists.ListCmd.Flags().BoolVarP(&CfgGlobal.ListCmd.GitFlag, "git", "g", false, "List all repositories from GITHUB") cmdLists.ListCmd.Flags().BoolVarP(&CfgGlobal.ListCmd.TeaFlag, "tea", "a", false, "List all repositories from GITEA") cmdLists.ListCmd.Flags().StringVarP(&CfgGlobal.ListCmd.User, "user", "u", "", "user for request on GITHUB or GITEA") cmdLists.ListCmd.Flags().StringVarP(&CfgGlobal.ListCmd.Organization, "org", "o", "", "List projects from an ORGANIZATION") // Create menu section cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.TokenEnv, "token", "t", "", "TOKEN for Gitea or Github") cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Organisation, "org", "o", "", "ORGANIZATION for this project") cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Name, "name", "n", "", "NAME of the Project") cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Description, "desc", "d", "", "DESCRIPTION of the project") cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.Private, "private", "p", false, "PRIVATE with this switch") // Env menu section cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesFlag, "group", "g", false, "GROUP environnement variables by categories") cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesListFlag, "list", "l", false, "LIST environnement variables") cmdEnv.EnvCmd.Flags().StringVarP(&CfgGlobal.EnvCmd.EnvVariablesFilter, "filter", "f", "", "HIGHLIGHT a specific word in environnement variables") cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesYmlFlag, "yml", "y", false, "YAML List environnement variables from config.yml") cmdEnv.EnvCmd.Flags().StringVarP(&CfgGlobal.EnvCmd.EnvVariablesCategory, "cat", "c", "", "FILTER for a specific category") cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesSetFlag, "set", "s", false, "Set environnement variable available from config.yml") cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesShowAllFlag, "all", "a", false, "Show all environnement variables") // Add subcommands rootCmd.AddCommand(cmdLists.ListCmd) rootCmd.AddCommand(cmdCreate.CreateCmd) rootCmd.AddCommand(cmdEnv.EnvCmd) } // function to print help or version func mainProgram(cmd *cobra.Command, args []string) { CfgGlobal.DebugPrintConfig("Function mainProgram") // print header if json flag is not set if !CfgGlobal.GetJsonFlag() { utils.PrintHeader() } // if version flag is set, print version and exit if CfgGlobal.GetVersionFlag() { utils.PrintVersion(version.GetFullVersion(), CfgGlobal.GetAuthor(), CfgGlobal.GetModifDate()) // if no flag is set, print help and exit } else { utils.PrintHelpFormated(version.GetFullVersion(), CfgGlobal.GetAuthor(), CfgGlobal.GetModifDate(), cmd) } } // main function func main() { //initialize config CfgGlobal.Init() cmdLists.InitConfig(CfgGlobal) cmdCreate.InitConfig(CfgGlobal) cmdEnv.InitConfig(CfgGlobal) // set debug mode CfgGlobal.SetDebugMode(false) CfgGlobal.DebugPrintConfig("Function main") // execute root command rootCmd.Execute() }