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 to manage projects development, environment variables develepment tools and more.", Long: `Simple cli to manage projects development, environment variables develepment tools and more.`, 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 // option : debug(d), version(V), help(h) // - - - - - - - - - - - rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.JsonFlag, "json", "j", false, "JSON output format") rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.VerboseFlag, "debug", "d", false, "Debug mode output") rootCmd.Flags().BoolVarP(&CfgGlobal.VersionFlag, "version", "V", false, "Show VERSION of "+CfgGlobal.GetApplicationName()) rootCmd.Flags().BoolP("help", "h", false, "Show help for "+CfgGlobal.GetApplicationName()) rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.Flags().SortFlags = false // List menu section // option : git(g), tea(a), search(s), user(u), org(o) // - - - - - - - - - - - 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, "search", "s", "", "search for request on GITHUB or 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") cmdLists.ListCmd.Flags().SortFlags = false // Create menu section (create project directories structure, init git, Github or Gitea repository, create README.md template ) // option : name(n), desc(d), struc(s), control(c), readme(r), token(t), org(o), private(p) // - - - - - - - - - - - - - - - - - - - // project informations 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") // project directories cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.DirectoryFlag, "struc", "s", false, "Create project STRUCTURE") // Project version cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.VersionFlag, "Control", "c", false, "Add version CONTROL to the project") // Project ReadMe cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.ReadmeFlag, "readme", "r", false, "Add ReadMe.md to the project") // Github or Gitea informations cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.TokenEnv, "token", "t", "", "TOKEN for Gitea or Github") cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Organization, "org", "o", "", "ORGANIZATION for this project") cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.PrivateFlag, "private", "p", false, "PRIVATE with this switch") cmdCreate.CreateCmd.Flags().SortFlags = false // Env menu section // option : group(g), list(l), filter(f), yml(y), cat(c), set(s), key(k), value(v), all(a) // - - - - - - - - - - - cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesListFlag, "list", "l", false, "==> LIST environnement variables") cmdEnv.EnvCmd.Flags().StringVarP(&CfgGlobal.EnvCmd.EnvVariablesFilter, "filter", "f", "", "(LIST) HIGHLIGHT a specific word in environnement variables") cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesSetFlag, "set", "s", false, "CREATE or modified environnement variable available from config.yml") // delete environnement variable flag cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesDeleteFlag, "DEL", "D", false, "DELETE environnement variable from config.yml") cmdEnv.EnvCmd.Flags().StringVarP(&CfgGlobal.EnvCmd.EnvVariablesKey, "key", "k", "", "(MODIF) create a KEY for environnement variable") cmdEnv.EnvCmd.Flags().StringVarP(&CfgGlobal.EnvCmd.EnvVariablesValue, "value", "v", "", "(MODIF) create a VALUE for environnement variable") cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesYmlFlag, "yml", "y", false, "==> YAML List environnement variables from config.yml") cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesFlag, "group", "g", false, "(YAML) GROUP environnement variables by categories") cmdEnv.EnvCmd.Flags().StringVarP(&CfgGlobal.EnvCmd.EnvVariablesCategory, "cat", "c", "", "(YAML) FILTER for a specific category") // cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesShowAllFlag, "all", "a", false, "Show all environnement variables") cmdEnv.EnvCmd.Flags().SortFlags = false // 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(true) CfgGlobal.SetDebugMode(false) CfgGlobal.DebugPrintConfig("Function main") // execute root command rootCmd.Execute() }