go-KodeStarter/kode-creator.go

137 lines
6.2 KiB
Go
Raw Permalink Normal View History

2023-06-12 22:40:22 -04:00
package main
import (
2023-06-30 15:25:39 -04:00
"kode-creator/cmdCreate"
"kode-creator/cmdEnv"
"kode-creator/cmdLists"
"kode-creator/config"
"kode-creator/utils"
"kode-creator/version"
2023-06-12 22:40:22 -04:00
"github.com/spf13/cobra"
)
2023-06-30 10:09:01 -04:00
// initailize global config
var CfgGlobal = &config.Config{}
// rootCmd represents the base command when called without any subcommands
2023-06-12 22:40:22 -04:00
var rootCmd = &cobra.Command{
2023-06-17 14:17:02 -04:00
Use: "kode-creator.exe",
2023-11-29 12:57:49 -05:00
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.`,
2023-06-12 22:40:22 -04:00
Run: func(cmd *cobra.Command, args []string) {
mainProgram(cmd, args)
},
}
2023-06-30 10:09:01 -04:00
// init function that will be executed before the main function
2023-06-12 22:40:22 -04:00
func init() {
2023-06-30 10:09:01 -04:00
CfgGlobal.Init()
2023-06-12 22:40:22 -04:00
2023-06-25 12:54:50 -04:00
// root menu section
2023-11-29 12:57:49 -05:00
// option : debug(d), version(V), help(h)
2023-07-01 00:49:45 -04:00
// - - - - - - - - - - -
2023-07-08 00:45:18 -04:00
rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.JsonFlag, "json", "j", false, "JSON output format")
2023-11-29 12:57:49 -05:00
rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.VerboseFlag, "debug", "d", false, "Debug mode output")
2023-06-30 10:09:01 -04:00
rootCmd.Flags().BoolVarP(&CfgGlobal.VersionFlag, "version", "V", false, "Show VERSION of "+CfgGlobal.GetApplicationName())
2023-07-08 00:45:18 -04:00
rootCmd.Flags().BoolP("help", "h", false, "Show help for "+CfgGlobal.GetApplicationName())
2023-06-25 12:54:50 -04:00
rootCmd.CompletionOptions.DisableDefaultCmd = true
2023-07-08 00:45:18 -04:00
rootCmd.Flags().SortFlags = false
2023-11-29 12:57:49 -05:00
2023-06-25 12:54:50 -04:00
// List menu section
2023-11-29 12:57:49 -05:00
// option : git(g), tea(a), search(s), user(u), org(o)
2023-07-01 00:49:45 -04:00
// - - - - - - - - - - -
2023-06-30 10:09:01 -04:00
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")
2023-07-08 00:45:18 -04:00
cmdLists.ListCmd.Flags().StringVarP(&CfgGlobal.ListCmd.User, "search", "s", "", "search for request on GITHUB or GITEA")
2023-06-30 10:09:01 -04:00
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")
2023-07-08 00:45:18 -04:00
cmdLists.ListCmd.Flags().SortFlags = false
2023-06-12 22:40:22 -04:00
2023-07-01 00:49:45 -04:00
// Create menu section (create project directories structure, init git, Github or Gitea repository, create README.md template )
2023-11-29 12:57:49 -05:00
// option : name(n), desc(d), struc(s), control(c), readme(r), token(t), org(o), private(p)
2023-07-01 00:49:45 -04:00
// - - - - - - - - - - - - - - - - - - -
// project informations
2023-06-30 10:09:01 -04:00
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")
2023-07-01 00:49:45 -04:00
// 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")
2023-07-08 00:45:18 -04:00
cmdCreate.CreateCmd.Flags().SortFlags = false
2023-06-12 22:40:22 -04:00
2023-06-25 12:54:50 -04:00
// Env menu section
2023-11-29 12:57:49 -05:00
// option : group(g), list(l), filter(f), yml(y), cat(c), set(s), key(k), value(v), all(a)
2023-07-01 00:49:45 -04:00
// - - - - - - - - - - -
2023-11-29 12:57:49 -05:00
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")
2023-07-08 00:45:18 -04:00
cmdEnv.EnvCmd.Flags().SortFlags = false
2023-06-21 11:50:12 -04:00
2023-06-25 12:54:50 -04:00
// Add subcommands
2023-06-21 11:50:12 -04:00
rootCmd.AddCommand(cmdLists.ListCmd)
rootCmd.AddCommand(cmdCreate.CreateCmd)
rootCmd.AddCommand(cmdEnv.EnvCmd)
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// function to print help or version
2023-06-12 22:40:22 -04:00
func mainProgram(cmd *cobra.Command, args []string) {
2023-06-30 15:25:39 -04:00
CfgGlobal.DebugPrintConfig("Function mainProgram")
// print header if json flag is not set
if !CfgGlobal.GetJsonFlag() {
utils.PrintHeader()
}
2023-06-25 12:54:50 -04:00
// if version flag is set, print version and exit
2023-06-30 10:09:01 -04:00
if CfgGlobal.GetVersionFlag() {
utils.PrintVersion(version.GetFullVersion(), CfgGlobal.GetAuthor(), CfgGlobal.GetModifDate())
2023-06-25 12:54:50 -04:00
// if no flag is set, print help and exit
2023-06-12 22:40:22 -04:00
} else {
2023-06-21 11:50:12 -04:00
2023-06-30 10:09:01 -04:00
utils.PrintHelpFormated(version.GetFullVersion(), CfgGlobal.GetAuthor(), CfgGlobal.GetModifDate(), cmd)
2023-06-30 15:25:39 -04:00
2023-06-12 22:40:22 -04:00
}
}
2023-06-30 10:09:01 -04:00
// main function
2023-06-12 22:40:22 -04:00
func main() {
2023-06-30 10:09:01 -04:00
//initialize config
CfgGlobal.Init()
cmdLists.InitConfig(CfgGlobal)
cmdCreate.InitConfig(CfgGlobal)
cmdEnv.InitConfig(CfgGlobal)
2023-06-24 02:00:53 -04:00
2023-06-30 10:09:01 -04:00
// set debug mode
2023-11-29 12:57:49 -05:00
// CfgGlobal.SetDebugMode(true)
CfgGlobal.SetDebugMode(false)
2023-06-30 10:09:01 -04:00
CfgGlobal.DebugPrintConfig("Function main")
2023-06-24 02:00:53 -04:00
2023-06-25 12:54:50 -04:00
// execute root command
2023-06-12 22:40:22 -04:00
rootCmd.Execute()
}