Skip to content

v1.18.7 - Universal Safety Flags

Release Date: March 24, 2026

Version 1.18.7 is a focused correctness release. The --dry-run, --force, and --backup flags introduced in v1.18.0 were registered but not actually wired through the generation pipeline — file writes still bypassed SafetyManager entirely. This release fully connects the safety layer across all 12 file-generating commands and every sub-generator they call.


What Changed

--dry-run, --force, --backup Now Work on All Commands

Prior to this release, only the feature command registered these flags. Running goca init --dry-run produced:

Error: unknown flag: --dry-run

All other commands silently ignored the flags even when passed. Starting in v1.18.7, every file-generating command honours them:

Command--dry-run--force--backup
goca entity
goca usecase
goca repository
goca handler
goca di
goca messages
goca interfaces
goca mocks
goca init
goca integrate
goca feature
goca test-integration

SafetyManager Wired Through All Generators

The root cause of the silent bypass was that writeFile() and writeGoFile() in cmd/utils.go wrote files directly via os.WriteFile without consulting SafetyManager. Generator functions (e.g. generateEntity, generateRepository) called these helpers directly, bypassing safety checks entirely.

Fix: Both helpers now accept an optional *SafetyManager parameter (variadic, backward-compatible):

go
// Before (wrote unconditionally)
func writeGoFile(path, content string) error

// After (routes through SafetyManager when provided)
func writeGoFile(path, content string, sm ...*SafetyManager) error

When a SafetyManager is passed, all writes route through SafetyManager.WriteFile() which handles:

  • Dry-run interception (prints preview, skips the write)
  • Conflict detection (rejects overwrite unless --force)
  • Backup creation (copies existing file to .goca-backup/ when --backup)

feature and integrate Now Thread SafetyManager Fully

Even in the feature command (which did have a SafetyManager), the manager was created at the top level but never forwarded into sub-generators. Each sub-generator independently called writeGoFile, bypassing it.

feature now passes safetyMgr to all sub-generators:

  • generateEntity(..., safetyMgr)
  • generateUseCaseWithFields(..., safetyMgr)
  • generateRepository(..., safetyMgr)
  • generateHandler(..., safetyMgr)
  • generateMessages(..., safetyMgr)
  • generateMocks(..., safetyMgr)
  • generateIntegrationTests(..., safetyMgr)
  • addEntityToAutoMigration(..., safetyMgr)

integrate threads SafetyManager through:

  • integrateFeaturescreateOrUpdateDIContainergenerateDI
  • updateMainGoWithAllFeaturescreateCompleteMainGoWithFeatures / addMissingFeaturesToMain

Usage Examples

Preview changes before generating

bash
goca feature Order --fields "UserID:uint,Total:float64" --dry-run
DRY-RUN MODE: Previewing changes without creating files

File                                          Action    Size
internal/domain/order.go                      create    1.2 KB
internal/usecase/order_service.go             create    2.4 KB
internal/repository/order_repository.go       create    1.6 KB
internal/handler/http/order_handler.go        create    2.9 KB

DRY-RUN SUMMARY: Would create 4 files

Regenerate safely with backup

bash
goca entity Product --fields "Name:string,Price:float64" --force --backup
Backed up: internal/domain/product.go -> .goca-backup/internal/domain/product.go.backup
Created:   internal/domain/product.go

Initialize a project safely

bash
goca init myapp --module github.com/acme/myapp --dry-run

Migration

No breaking changes. All generator function signatures remain backward-compatible — callers that do not provide a SafetyManager continue to work exactly as before.


Files Modified

15 files were modified across the cmd/ package:

  • cmd/utils.go — variadic sm ...*SafetyManager parameter on writeFile and writeGoFile
  • cmd/entity.go, cmd/usecase.go, cmd/repository.go, cmd/handler.go — flags registered, SafetyManager threaded
  • cmd/di.go, cmd/messages.go, cmd/interfaces.go, cmd/mocks.go — flags registered, SafetyManager threaded
  • cmd/init.go, cmd/integrate.go, cmd/feature.go, cmd/test_integration.go — SafetyManager forwarded to sub-generators
  • cmd/automigrate.go, cmd/data_generator.go — updated to accept variadic SafetyManager

Released under the MIT License.