go-KodeStarter/cmdCreate/create.go

103 lines
2.3 KiB
Go
Raw Permalink Normal View History

2023-06-21 11:50:12 -04:00
package cmdCreate
2023-06-12 22:40:22 -04:00
2023-06-17 14:17:02 -04:00
import (
"fmt"
2023-06-30 15:25:39 -04:00
"kode-creator/config"
"kode-creator/structures"
"kode-creator/utils"
2023-06-17 14:17:02 -04:00
"log"
"github.com/joho/godotenv"
"github.com/spf13/cobra"
)
var token, org, name, private, description string
2023-06-30 10:09:01 -04:00
// 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
}
2023-06-17 14:17:02 -04:00
var CreateCmd = &cobra.Command{
Use: "create",
2023-07-08 00:45:18 -04:00
Short: "CREATE Github project",
2023-06-17 14:17:02 -04:00
Long: `A simple CLI app to create a startup project on Github`,
Run: func(cmd *cobra.Command, args []string) {
2023-06-30 10:09:01 -04:00
err := CreateProject(cmd, args)
2023-06-17 14:17:02 -04:00
if err != nil {
fmt.Println("Error:", err)
return
}
},
}
2023-07-01 00:49:45 -04:00
// The CreateProject function creates a project structure, including a directory, version control, and
// a readme file, based on the provided arguments and flags.
2023-06-30 10:09:01 -04:00
func CreateProject(cmd *cobra.Command, args []string) error {
2023-06-17 14:17:02 -04:00
godotenv.Load()
2023-06-30 10:09:01 -04:00
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()
}
2023-06-17 14:17:02 -04:00
// Construct POST data
data := structures.Project{
Name: name,
Description: description,
Private: private == "true",
}
2023-06-30 10:09:01 -04:00
data.Name = CfgGlobal.GetCreateName()
data.Description = CfgGlobal.GetCreateDescription()
2023-06-17 14:17:02 -04:00
fmt.Println("Structure Name:" + data.Name)
2023-07-01 00:49:45 -04:00
// 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...")
}
2023-07-08 00:45:18 -04:00
}
// 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")
2023-07-01 00:49:45 -04:00
}
}
// if github flag is set, create structure in github
2023-07-08 00:45:18 -04:00
if CfgGlobal.GetCreateTeaFlag() {
2023-07-01 00:49:45 -04:00
} else if CfgGlobal.GetCreateTeaFlag() {
err := CreateGiteaProject(data, cmd, args)
if err != nil {
log.Fatal(err)
}
}
return nil
}