fix(cli): require an initialized project before save/restore/history (#9)#42
Merged
Merged
Conversation
) Running `eko save`, `eko restore` or `eko history` outside an initialized project gave a confusing experience: `save` silently created a `.eko` tree but failed to record the snapshot (the table doesn't exist yet), and `restore`/`history` opened a non-existent database and did nothing useful. Add a shared `requireInitialized` PreRunE guard that checks for the `.eko` directory and, when missing, fails early with a clear message pointing at `eko init`. Root command now silences Cobra's duplicate error/usage output so the guidance is printed once, on stderr. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9.
Running a command in a directory that hasn't been initialized currently fails in a confusing way:
eko savecallssnapshot.CreateSnapshot()(which creates a.eko/snapshots/...tree) and then inserts into asnapshotstable that doesn't exist yet — so it printsSnapshot saved: <id>but the snapshot is never actually recorded.eko restore/eko historyopen.eko/db.sqlitefor a project that isn't there and silently do nothing.Change
Add a small shared guard,
requireInitialized, wired in as a CobraPreRunEonsave,restoreandhistory. If there's no.ekodirectory it fails early with a helpful message:inititself is unaffected, and the happy path (eko init→eko save→eko history) works as before.The root command now sets
SilenceUsage/SilenceErrorsso the guidance is printed exactly once (on stderr) instead of being duplicated and followed by a usage dump, which is Cobra's default for aPreRunEerror.Tests / verification
cmd/project_test.gocoversisInitialized(missing.eko, present.eko, and a plain file named.ekowhich must not count) andrequireInitialized(helpful error when missing, nil when present), usingt.Chdir+t.TempDir.go test ./cmd/passes; built the CLI with-tags no_guiand verified the behaviour above end to end.I scoped the guard to the three data commands named in the issue. Happy to extend it or adjust the wording if you'd prefer.
🤖 Generated with Claude Code