build 0.0.0.25
This commit is contained in:
+22
-13
@@ -18,15 +18,20 @@ import (
|
||||
|
||||
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) {
|
||||
|
||||
config.SetInformations(cmd, args)
|
||||
|
||||
err := CreateProject()
|
||||
err := CreateProject(cmd, args)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
return
|
||||
@@ -34,15 +39,19 @@ var CreateCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func CreateProject() error {
|
||||
func CreateProject(cmd *cobra.Command, args []string) error {
|
||||
|
||||
godotenv.Load()
|
||||
|
||||
fmt.Printf("Token: %s\n", config.GetToken())
|
||||
fmt.Printf("Name: %s\n", config.GetCreateName())
|
||||
fmt.Printf("Description: %s\n", config.GetCreateDescription())
|
||||
fmt.Printf("Private: %s\n", config.GetCreatePrivate())
|
||||
fmt.Printf("Org: %s\n", config.GetCreateOrganisation())
|
||||
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{
|
||||
@@ -51,8 +60,8 @@ func CreateProject() error {
|
||||
Private: private == "true",
|
||||
}
|
||||
|
||||
data.Name = config.GetCreateName()
|
||||
data.Description = config.GetCreateDescription()
|
||||
data.Name = CfgGlobal.GetCreateName()
|
||||
data.Description = CfgGlobal.GetCreateDescription()
|
||||
|
||||
fmt.Println("Structure Name:" + data.Name)
|
||||
|
||||
@@ -60,9 +69,9 @@ func CreateProject() error {
|
||||
jsonData, _ := json.Marshal(data)
|
||||
|
||||
req, err := http.NewRequest("POST",
|
||||
fmt.Sprintf("%s/%s/repos", config.GetUrlApiOrgs(), config.GetCreateOrganisation()),
|
||||
fmt.Sprintf("%s/%s/repos", CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetCreateCmd().Organisation),
|
||||
bytes.NewBuffer(jsonData))
|
||||
req.Header.Set("Authorization", "token "+config.GetToken())
|
||||
req.Header.Set("Authorization", "token "+CfgGlobal.GetTokenEnv())
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
client := &http.Client{}
|
||||
res, err := client.Do(req)
|
||||
|
||||
Reference in New Issue
Block a user