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-06-12 22:40:22 -04:00
|
|
|
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)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
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-06-30 10:09:01 -04:00
|
|
|
rootCmd.Flags().BoolP("help", "h", false, "Show help for "+CfgGlobal.GetApplicationName())
|
|
|
|
rootCmd.Flags().BoolVarP(&CfgGlobal.VersionFlag, "version", "V", false, "Show VERSION of "+CfgGlobal.GetApplicationName())
|
2023-06-25 12:54:50 -04:00
|
|
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
2023-06-30 10:09:01 -04:00
|
|
|
rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.VerboseFlag, "verbose", "v", false, "VERBOSE mode output")
|
|
|
|
rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.JsonFlag, "json", "j", false, "JSON output format")
|
2023-06-12 22:40:22 -04:00
|
|
|
|
2023-06-25 12:54:50 -04:00
|
|
|
// List menu section
|
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")
|
|
|
|
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-06-12 22:40:22 -04:00
|
|
|
|
2023-06-25 12:54:50 -04:00
|
|
|
// Create menu section
|
2023-06-30 10:09:01 -04:00
|
|
|
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")
|
2023-06-12 22:40:22 -04:00
|
|
|
|
2023-06-25 12:54:50 -04:00
|
|
|
// Env menu section
|
2023-06-30 10:09:01 -04:00
|
|
|
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")
|
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
|
|
|
|
CfgGlobal.SetDebugMode(false)
|
|
|
|
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()
|
|
|
|
|
|
|
|
}
|