Skip to content

Commit 2e4217e

Browse files
committed
fix: cli problem
1 parent ac0b1e5 commit 2e4217e

File tree

7 files changed

+17
-123
lines changed

7 files changed

+17
-123
lines changed

cmd/new.go

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
2+
23
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
4+
35
*/
6+
47
package cmd
58

69
import (
@@ -19,8 +22,8 @@ import (
1922
// newCmd represents the new command
2023
var newCmd = &cobra.Command{
2124
Use: "new",
22-
Short: "this command for creating a new project.",
23-
Long: `this command for creating a new project.`,
25+
Short: "command for creating a new project.",
26+
Long: `command for creating a new project.`,
2427
Run: func(cmd *cobra.Command, args []string) {
2528
// Check if the project name is provided
2629
if len(args) < 1 {
@@ -35,7 +38,6 @@ var newCmd = &cobra.Command{
3538
dirName := args[0]
3639

3740
// Create the new project
38-
// Renaming argument for clarity
3941
createNewProject(dirName, projectRouter, tmpl, cmd.OutOrStdout())
4042
},
4143
}
@@ -54,37 +56,27 @@ func init() {
5456
newCmd.Flags().StringVar(&projectRouter, "router", "", "router of the project")
5557
}
5658

57-
// Renamed 'template' to 'tmpl' for consistency with usage in newCmd.Run
58-
func createNewProject(projectName string, projectRouter string, tmpl string, out io.Writer) {
59-
// Create the project root directory
59+
func createNewProject(projectName string, projectRouter string, template string, out io.Writer) {
6060
err := os.Mkdir(projectName, 0755)
6161
if err != nil {
6262
fmt.Fprintf(out, "Error creating directory: %v\n", err)
6363
return
6464
}
65+
// Print the template that was passed
6566

66-
// Template Data structure for rendering
67-
data := TemplateData{
67+
// Always add README + Makefile from common
68+
renderTemplateDir("common", projectName, TemplateData{
6869
ModuleName: projectName,
6970
PortName: projectPort,
70-
}
71-
72-
fmt.Println("data templateData: ", data.ModuleName, data.PortName)
71+
})
7372

74-
// Always add README + Makefile from common
75-
// FIX: Path corrected to "common" since templates.FS root is the templates/ directory content.
76-
err = renderTemplateDir("common", projectName, data)
77-
if err != nil {
78-
fmt.Fprintf(out, "Error rendering common templates: %v\n", err)
79-
return
80-
}
73+
renderTemplateDir("rest", projectName, TemplateData{
74+
ModuleName: projectName,
75+
PortName: projectPort,
76+
})
8177

82-
// Render project specific templates (e.g., "rest/gin")
83-
// FIX: Path corrected to remove redundant "templates/" prefix.
84-
err = renderTemplateDir(tmpl+"/"+projectRouter, projectName, data)
85-
// FIX: Correctly checking the error returned by the function call above.
8678
if err != nil {
87-
fmt.Fprintf(out, "Error rendering project templates: %v\n", err)
79+
fmt.Fprintf(out, "Error rendering templates: %v\n", err)
8880
return
8981
}
9082

@@ -107,18 +99,16 @@ func renderTemplateDir(templatePath, destinationPath string, data TemplateData)
10799
targetPath := filepath.Join(destinationPath, strings.TrimSuffix(relPath, ".tmpl"))
108100

109101
if d.IsDir() {
110-
// This path is necessary to create all subdirectories correctly
111102
return os.MkdirAll(targetPath, 0755)
112103
}
113104

114-
// Read file content from the embedded filesystem
105+
// ✅ Important: use full `path` for ReadFile
115106
content, err := templates.FS.ReadFile(path)
116107
if err != nil {
117108
return err
118109
}
119110

120111
// Parse template
121-
// Note: filepath.Base(path) uses the original path inside the embedded FS
122112
tmpl, err := template.New(filepath.Base(path)).Parse(string(content))
123113
if err != nil {
124114
return err

neew/cmd/main.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

neew/go.mod

Lines changed: 0 additions & 7 deletions
This file was deleted.

neew/internal/config/config.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

neew/internal/handler/user_handler.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

neew/internal/routers/routes.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

templates/common/README.md.tmpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# {{ .ProjectName }}
1+
# {{ .ModuleName }}
22

3-
Generated with go-scaffold (framework: {{ .Framework }}).
43

54
## 🚀 Run
65
```bash

0 commit comments

Comments
 (0)