← back to Cli Printing Press
fix(generate): reject non-empty output directory without --force
862dfa705efaa7a0375a1de943132be580cbfca1 · 2026-03-27 13:32:36 -0700 · Trevin Chow
Prevents silent file overwrites when running generate twice on the same
output directory. Empty pre-existing directories are still allowed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit 862dfa705efaa7a0375a1de943132be580cbfca1
Author: Trevin Chow <trevin@trevinchow.com>
Date: Fri Mar 27 13:32:36 2026 -0700
fix(generate): reject non-empty output directory without --force
Prevents silent file overwrites when running generate twice on the same
output directory. Empty pre-existing directories are still allowed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---
internal/cli/root.go | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/internal/cli/root.go b/internal/cli/root.go
index 68b169d8..10517d6b 100644
--- a/internal/cli/root.go
+++ b/internal/cli/root.go
@@ -103,6 +103,11 @@ func newGenerateCmd() *cobra.Command {
if err := os.RemoveAll(absOut); err != nil {
return fmt.Errorf("removing existing output dir: %w", err)
}
+ } else if info, err := os.Stat(absOut); err == nil && info.IsDir() {
+ entries, _ := os.ReadDir(absOut)
+ if len(entries) > 0 {
+ return fmt.Errorf("output directory %s already exists (use --force to overwrite)", absOut)
+ }
}
gen := generator.New(parsed, absOut)
@@ -187,6 +192,11 @@ func newGenerateCmd() *cobra.Command {
if err := os.RemoveAll(absOut); err != nil {
return fmt.Errorf("removing existing output dir: %w", err)
}
+ } else if info, err := os.Stat(absOut); err == nil && info.IsDir() {
+ entries, _ := os.ReadDir(absOut)
+ if len(entries) > 0 {
+ return fmt.Errorf("output directory %s already exists (use --force to overwrite)", absOut)
+ }
}
gen := generator.New(apiSpec, absOut)
← df0474e8 docs: split CLAUDE.md into AGENTS.md for Codex compatibility
·
back to Cli Printing Press
·
feat(cli): add --json flag to generate, print, and vision co 7f5c3520 →