fixing errors to ensure generate works

This commit is contained in:
2021-08-30 16:59:33 +04:00
parent ce5b7aa1af
commit c3a3a21132
3 changed files with 56 additions and 5 deletions

View File

@@ -249,15 +249,23 @@ var CliAction = func(ctx *cli.Context) error {
// of the project is created to repurpose // of the project is created to repurpose
// the project for custom purpose // the project for custom purpose
if Generate != "" { if Generate != "" {
err := generate.GenerateNewProject(Generate,"test") var err error
// If the module name is provided
if Modulename != "" {
err = generate.GenerateNewProject(Generate,Modulename)
} else {
err = generate.GenerateNewProject(Generate,Generate)
}
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} else { } else {
fmt.Println("Created new folder: " + Generate) fmt.Println("Created new folder: " + Generate)
fmt.Println("1. Enter inside " + Generate + "directory") fmt.Println("1. Enter inside " + Generate + " directory")
fmt.Println("2. go mod init <name of your module (ex: github.com/akilan1999/lol)>") fmt.Println("2. git remote add " + Generate + " <PATH to the github repo>")
fmt.Println("3. sh install.sh " + Generate) fmt.Println("3. git push " + Generate + " <PATH to the github repo>")
fmt.Println("4. ./" + Generate + " -h (This is to test if the binary is working") fmt.Println("4. go mod tidy")
fmt.Println("5. sh install.sh " + Generate)
fmt.Println("6. ./" + Generate + " -h (This is to test if the binary is working)")
} }
} }
//-------------------------------- //--------------------------------

View File

@@ -31,6 +31,7 @@ var (
// Generate only allowed in dev release // Generate only allowed in dev release
// -- REMOVE ON REGULAR RELEASE -- // -- REMOVE ON REGULAR RELEASE --
Generate string Generate string
Modulename string
//-------------------------------- //--------------------------------
) )
@@ -200,5 +201,12 @@ var AppConfigFlags = []cli.Flag{
EnvVars: []string{"GENERATE"}, EnvVars: []string{"GENERATE"},
Destination: &Generate, Destination: &Generate,
}, },
&cli.StringFlag{
Name: "ModuleName",
Aliases: []string{"mod"},
Usage: "New go project module name",
EnvVars: []string{"MODULENAME"},
Destination: &Modulename,
},
//-------------------------------- //--------------------------------
} }

View File

@@ -69,7 +69,11 @@ func GenerateNewProject(name string, module string) error {
// Action performed: // Action performed:
// - Ensuring main.go file exists // - Ensuring main.go file exists
// - Ensuring generate.go file exists // - Ensuring generate.go file exists
// - Ensuring modifyGenerate.go file exists
// - Ensuring generate_test.go file exists
// - Ensuring server/server.go file exists // - Ensuring server/server.go file exists
// - Ensuring server/gopsutil.go file exists
// - Ensuring server/gpu.go file exists
// - Ensuring cmd/action.go file exists // - Ensuring cmd/action.go file exists
// - Ensuring cmd/flags.go file exists // - Ensuring cmd/flags.go file exists
// - Skipping all .go files apart from the ones listed above // - Skipping all .go files apart from the ones listed above
@@ -85,12 +89,24 @@ func GenerateNewProject(name string, module string) error {
return false, nil return false, nil
case strings.HasSuffix(src, "generate.go"): case strings.HasSuffix(src, "generate.go"):
return false, nil return false, nil
case strings.HasSuffix(src, "modifyGenerate.go"):
return false, nil
case strings.HasSuffix(src, "generate_test.go"):
return false, nil
case strings.HasSuffix(src, "server/server.go"): case strings.HasSuffix(src, "server/server.go"):
return false, nil return false, nil
case strings.HasSuffix(src, "server/gopsutil.go"):
return false, nil
case strings.HasSuffix(src, "server/gpu.go"):
return false, nil
case strings.HasSuffix(src, "cmd/action.go"): case strings.HasSuffix(src, "cmd/action.go"):
return false, nil return false, nil
case strings.HasSuffix(src, "cmd/flags.go"): case strings.HasSuffix(src, "cmd/flags.go"):
return false, nil return false, nil
case strings.HasSuffix(src, "config/config.go"):
return false, nil
case strings.HasSuffix(src, "config/config_test.go"):
return false, nil
case strings.HasSuffix(src, ".go"): case strings.HasSuffix(src, ".go"):
return true, nil return true, nil
case strings.HasSuffix(src, "go.mod"): case strings.HasSuffix(src, "go.mod"):
@@ -194,6 +210,7 @@ func (a *NewProject) ChangeImportFiles() error {
// Action performed: // Action performed:
// Files we would need to modify the imports in // Files we would need to modify the imports in
// - generate/generate.go -> config module // - generate/generate.go -> config module
// - generate/generate_test.go -> config module
// - cmd/action.go -> config module, server module, generate module // - cmd/action.go -> config module, server module, generate module
// - cmd/flags.go -> config module, server module, generate module // - cmd/flags.go -> config module, server module, generate module
// - server/server.go -> config module // - server/server.go -> config module
@@ -218,6 +235,24 @@ func (a *NewProject) ChangeImportFiles() error {
if err != nil { if err != nil {
return err return err
} }
//-----------------------------------------------------------------
// 1.1 - generate/generate_test.go -> config module
a.FileNameAST = a.NewDir + "generate/generate_test.go"
// Get AST information of the file
err = a.GetASTGoFile()
if err != nil {
return err
}
// Change the appropriate Go file
err = a.ChangeImports(a.CurrentModule+"/config", a.Module+"/config")
if err != nil {
return err
}
// Writes the change to the appropriate file
err = a.WriteGoAst()
if err != nil {
return err
}
//----------------------------------------------------------------- //-----------------------------------------------------------------
//----------------------------------------------------------------- //-----------------------------------------------------------------