Skip to content

feat: add zemo dump to print all memos#8

Merged
hidetzu merged 2 commits into
mainfrom
feat/zemo-dump
May 6, 2026
Merged

feat: add zemo dump to print all memos#8
hidetzu merged 2 commits into
mainfrom
feat/zemo-dump

Conversation

@hidetzu
Copy link
Copy Markdown
Owner

@hidetzu hidetzu commented May 6, 2026

Summary

Add a zemo dump subcommand that prints scratch and every topic to stdout under === <name> === section headers, ordered as scratch first then topics alphabetically. Read-only — no git operations. Completes the search/discovery primitive set (ls / cat / dump) so terminal-side search such as WezTerm QuickSearch can grep across all memos in a single pass.

This PR also bumps the version to 0.2.0, intended to be tagged immediately after merge.

Related issue

Closes #5

Changes

  • New Command.dump variant in cli.zig; routed from parseArgs (rejects extra args) and dispatched in run.
  • New doDump (env → memo dir) and dumpMemos (path-based, testable) helpers.
  • Section header format: === scratch === for scratch, === <topic> === for each topic. Blank lines before/after the header for readability; previous-section trailing-newline tracking avoids accidental double blanks between sections.
  • Targets: <memo>/scratch.txt (printed first if present) followed by alphabetically sorted <memo>/topics/*.md. Subdirectories and non-.md files under topics/ are excluded. Missing scratch / missing topics/ are skipped silently (exit 0 with no output if both are missing).
  • File contents streamed via Io.Reader.streamRemaining (4 KiB read buffer) — bounded memory regardless of file size.
  • Refactored: listTopics was split — directory iteration / filter / sort moved into a shared collectTopicNames helper that both listTopics and dumpMemos call. errdefer (not defer) is used in the helper so the returned list is not freed on success.
  • README: added zemo dump to Features and Usage sections.
  • HELP_TEXT: added zemo dump line.
  • Version bump: VERSION constant in cli.zig updated from 0.1.0 to 0.2.0. After merge, tag v0.2.0 to trigger the release workflow (binaries + auto-generated release notes covering feat: add zemo ls to list topics #6 ls, feat: add zemo cat to print memo to stdout #7 cat, feat: add zemo dump to print all memos #8 dump, plus the relative-ZEMO_DIR fix from feat: add zemo ls to list topics #6).

Testing

  • zig build test passes locally
  • Manually verified the affected command(s) (zig build run -- dump against ~/memo, zig build run -- --version reports zemo 0.2.0)
  • Cross-build check (if touching platform-specific code): zig build -Dtarget=x86_64-windows / -Dtarget=x86_64-macos

New tests added:

  • parseArgs: dump subcommand — parser-level
  • dumpMemos: scratch only — only scratch present
  • dumpMemos: topics only sorted and filtered — alphabetical sort, .md filter, subdirectory exclusion
  • dumpMemos: scratch and topics — full combined output, including blank-line spacing across sections with/without trailing newlines
  • dumpMemos: neither scratch nor topics prints nothing — empty memo case
  • doDump: uses ZEMO_DIR override — end-to-end through env-map resolution

Notes for reviewers

  • The blank-line handling in writeSectionHeader (previous_ended_with_newline + wrote_any flags) is what enables the spec'd === a ===\n\n<a>\n\n=== b ===\n\n<b> shape regardless of whether each file ends with a trailing newline. Tests cover both shapes.
  • Extracting collectTopicNames was a deliberate scope addition to avoid duplicating the iterate-filter-sort logic between listTopics and dumpMemos. The change to listTopics is mechanical (delegates to the helper) and remains covered by its existing test.
  • Test helpers writeTestFile / tmpDirPath are new — small wrappers used by the four dumpMemos tests to keep each test focused on the assertions rather than tmp-dir bookkeeping.
  • Version bump is included in this PR so that "merge → tag" is a single step. After merge: git checkout main && git pull && git tag v0.2.0 && git push origin v0.2.0.

@hidetzu hidetzu merged commit 70d1cdf into main May 6, 2026
6 checks passed
@hidetzu hidetzu deleted the feat/zemo-dump branch May 6, 2026 10:04
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.

feat: add zemo dump command

1 participant