package cmdCreate import ( "fmt" "kode-creator/config" "kode-creator/structures" "kode-creator/utils" "log" "github.com/joho/godotenv" "github.com/spf13/cobra" ) var token, org, name, private, description string // initailize global config var CfgGlobal *config.Config // Declare a global variable for config func InitConfig(config *config.Config) { CfgGlobal = config // Assign the passed config to the global variable } var CreateCmd = &cobra.Command{ Use: "create", Short: "CREATE Github project", Long: `A simple CLI app to create a startup project on Github`, Run: func(cmd *cobra.Command, args []string) { err := CreateProject(cmd, args) if err != nil { fmt.Println("Error:", err) return } }, } // The CreateProject function creates a project structure, including a directory, version control, and // a readme file, based on the provided arguments and flags. func CreateProject(cmd *cobra.Command, args []string) error { godotenv.Load() CfgGlobal.DebugPrintConfig("Function CreateProject") // initialize global config for command list CfgGlobal.InitCmdCreate(cmd, args) // print header if json flag is not set if !CfgGlobal.GetJsonFlag() { utils.PrintHeader() } // Construct POST data data := structures.Project{ Name: name, Description: description, Private: private == "true", } data.Name = CfgGlobal.GetCreateName() data.Description = CfgGlobal.GetCreateDescription() fmt.Println("Structure Name:" + data.Name) // if directory flag is set, create structure in current directory if CfgGlobal.GetCreateDirectoryFlag() { // Create directory of the project CreateProjectStructure(data) // if version flag is set, create version control in project if CfgGlobal.GetCreateVersionFlag() { fmt.Println("==> Creating version control...") } } // if readme flag is set, create readme in project if CfgGlobal.GetCreateReadmeFlag() { fmt.Println("==> Creating readme...") isCreated := CreateReadme(name, description, "BC", "") if isCreated { fmt.Println("==> Created README.md") } } // if github flag is set, create structure in github if CfgGlobal.GetCreateTeaFlag() { } else if CfgGlobal.GetCreateTeaFlag() { err := CreateGiteaProject(data, cmd, args) if err != nil { log.Fatal(err) } } return nil }