Skip to content

Deduplicate DB lifecycle management in CLI commands#14

Merged
JulienTant merged 1 commit intomainfrom
worktree-agent-a3ca822d
Apr 4, 2026
Merged

Deduplicate DB lifecycle management in CLI commands#14
JulienTant merged 1 commit intomainfrom
worktree-agent-a3ca822d

Conversation

@JulienTant
Copy link
Copy Markdown
Owner

@JulienTant JulienTant commented Apr 4, 2026

Summary

  • Extracts repeated database open/defer-close boilerplate into a withDatabase helper function
  • Refactors all 9 CLI commands (add, remove, blogs, scan, articles, read, read-all, unread, import) to use the helper
  • Net reduction of 52 lines with zero behavioral changes

Test plan

  • All 48 existing unit + e2e tests pass unchanged
  • golangci-lint reports 0 issues
  • E2E golden files require no updates (output is identical)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized CLI command handling to reduce code duplication and improve maintainability.

Extract repeated database open/defer-close boilerplate into a withDatabase
helper, reducing duplication across all 9 CLI commands.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8795313d-0171-4427-a307-68980079b9d4

📥 Commits

Reviewing files that changed from the base of the PR and between 52fb078 and eb4fdea.

📒 Files selected for processing (1)
  • internal/cli/commands.go

📝 Walkthrough

Walkthrough

Refactored CLI command handlers in a single file by extracting shared database initialization and cleanup logic into a new withDatabase() helper function. All nine command handlers (add, remove, blogs, scan, articles, read, read-all, unread, import) were updated to use this helper, consolidating duplicate storage.OpenDatabase() and defer db.Close() patterns.

Changes

Cohort / File(s) Summary
Database Handler Refactoring
internal/cli/commands.go
Introduced shared withDatabase() helper that centralizes database opening, error handling, and resource cleanup. Refactored nine CLI command handlers to use this helper instead of inline database initialization, eliminating duplicate code while preserving existing command logic and error reporting flows.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A helper hops in, so neat and so clean,
Nine commands rejoice—duplication unseen!
With withDatabase bound, the database song,
Now flows through the code where it all should belong.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing a shared helper function to deduplicate database lifecycle management code across CLI commands.
Description check ✅ Passed The description includes all required template sections (Summary and Test plan) with comprehensive details about what was changed, how it was tested, and verification that all checks pass.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-agent-a3ca822d

Comment @coderabbitai help to get the list of available commands and usage tips.

@JulienTant JulienTant merged commit d2189e3 into main Apr 4, 2026
2 checks passed
@JulienTant JulienTant deleted the worktree-agent-a3ca822d branch April 4, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant