Skip to content

Commit 5197e81

Browse files
committed
fix path
1 parent 2c21274 commit 5197e81

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

main.go

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,14 @@ A Go project created with gocar.
210210
## Build
211211
212212
`+"```bash"+`
213-
# Debug build
213+
# Debug build (current platform)
214214
gocar build
215215
216-
# Release build
216+
# Release build (current platform)
217217
gocar build --release
218+
219+
# Cross-compile for Linux on AMD64
220+
gocar build --target linux/amd64
218221
`+"```"+`
219222
220223
## Run
@@ -223,11 +226,26 @@ gocar build --release
223226
gocar run
224227
`+"```"+`
225228
226-
## Output
229+
## Output Structure
230+
231+
`+"```"+`
232+
bin/
233+
├── debug/
234+
│ └── <os>-<arch>/
235+
│ └── %s
236+
└── release/
237+
└── <os>-<arch>/
238+
└── %s
239+
`+"```"+`
240+
241+
Build artifacts are organized by:
242+
- **Build mode**: debug or release
243+
- **Target platform**: OS and architecture (e.g., linux-amd64, darwin-arm64)
227244
228-
- Debug build: `+"`./bin/%s`"+`
229-
- Release build: `+"`./bin/%s`"+` (with release flags: CGO_ENABLED=0 -ldflags="-s -w" -trimpath)
230-
`, appName, appName, appName)
245+
Examples:
246+
- Debug build for current platform: `+"`./bin/debug/linux-amd64/%s`"+`
247+
- Release build for Windows: `+"`./bin/release/windows-amd64/%s.exe`"+`
248+
`, appName, appName, appName, appName, appName)
231249

232250
if err := writeFile(filepath.Join(appName, "README.md"), readme); err != nil {
233251
return err
@@ -344,11 +362,14 @@ A Go project created with gocar (project mode).
344362
## Build
345363
346364
`+"```bash"+`
347-
# Debug build
365+
# Debug build (current platform)
348366
gocar build
349367
350-
# Release build
368+
# Release build (current platform)
351369
gocar build --release
370+
371+
# Cross-compile for Linux
372+
gocar build --target linux/amd64
352373
`+"```"+`
353374
354375
## Run
@@ -357,18 +378,33 @@ gocar build --release
357378
gocar run
358379
`+"```"+`
359380
360-
## Output
381+
## Output Structure
382+
383+
`+"```"+`
384+
bin/
385+
├── debug/
386+
│ └── <os>-<arch>/
387+
│ └── %s
388+
└── release/
389+
└── <os>-<arch>/
390+
└── %s
391+
`+"```"+`
392+
393+
Build artifacts are organized by:
394+
- **Build mode**: debug or release
395+
- **Target platform**: OS and architecture (e.g., linux-amd64, darwin-arm64)
361396
362-
- Debug build: `+"`./bin/%s`"+`
363-
- Release build: `+"`./bin/%s`"+` (with release flags: CGO_ENABLED=0 -ldflags="-s -w" -trimpath)
397+
Examples:
398+
- Debug build for current platform: `+"`./bin/debug/linux-amd64/%s`"+`
399+
- Release build for Windows: `+"`./bin/release/windows-amd64/%s.exe`"+`
364400
365401
## Directories
366402
367403
- **cmd/**: Main applications for this project
368404
- **internal/**: Private application and library code (not importable by other projects)
369405
- **pkg/**: Library code that can be used by external applications
370406
- **test/**: Integration tests, black-box tests
371-
`, appName, appName, appName, appName)
407+
`, appName, appName, appName, appName, appName, appName)
372408

373409
if err := writeFile(filepath.Join(appName, "README.md"), readme); err != nil {
374410
return err
@@ -446,7 +482,7 @@ EXAMPLES:
446482
gocar build --release --target linux/arm64 Cross-compile for Linux ARM (release)
447483
448484
COMMON TARGETS:
449-
linux/amd64 Linux 64-bit
485+
linux/amd64 Linux AMD 64-bit
450486
linux/arm64 Linux ARM 64-bit
451487
linux/arm Linux ARM 32-bit
452488
darwin/amd64 macOS Intel
@@ -589,9 +625,9 @@ func handleRun(args []string) {
589625
// Determine source path based on project mode
590626
var sourcePath string
591627
if projectMode == "project" {
592-
sourcePath = "./cmd/server/main.go"
628+
sourcePath = "./cmd/server"
593629
} else {
594-
sourcePath = "./main.go"
630+
sourcePath = "."
595631
}
596632

597633
fmt.Printf("Running %s...\n\n", appName)
@@ -704,13 +740,16 @@ func detectProject() (projectRoot, appName, projectMode string, err error) {
704740
// Get app name from directory name
705741
appName = filepath.Base(projectRoot)
706742

707-
// Detect project mode
708-
if _, err := os.Stat(filepath.Join(projectRoot, "cmd", "server", "main.go")); err == nil {
743+
// Detect project mode: prioritize checking directory structure
744+
// Check for project mode first (cmd/server directory exists)
745+
cmdServerDir := filepath.Join(projectRoot, "cmd", "server")
746+
if stat, err := os.Stat(cmdServerDir); err == nil && stat.IsDir() {
709747
projectMode = "project"
710748
} else if _, err := os.Stat(filepath.Join(projectRoot, "main.go")); err == nil {
749+
// Simple mode: main.go in root
711750
projectMode = "simple"
712751
} else {
713-
return "", "", "", fmt.Errorf("cannot detect project mode: no main.go or cmd/server/main.go found")
752+
return "", "", "", fmt.Errorf("cannot detect project mode: no main.go found and cmd/server directory doesn't exist")
714753
}
715754

716755
return projectRoot, appName, projectMode, nil

0 commit comments

Comments
 (0)