Skip to content

feat: add zemo cat to print memo to stdout#7

Merged
hidetzu merged 1 commit into
mainfrom
feat/zemo-cat
May 6, 2026
Merged

feat: add zemo cat to print memo to stdout#7
hidetzu merged 1 commit into
mainfrom
feat/zemo-cat

Conversation

@hidetzu
Copy link
Copy Markdown
Owner

@hidetzu hidetzu commented May 6, 2026

Summary

Add a zemo cat subcommand that prints memo content to stdout. With no argument it prints <memo>/scratch.txt; with a topic argument it prints <memo>/topics/<topic>.md. Read-only — no git operations are performed. Builds the second primitive (after zemo ls) for the search/discovery flow that delegates filtering to terminal-side search such as WezTerm QuickSearch.

Related issue

Closes #4

Changes

  • New Command.cat: ?[]const u8 variant in cli.zig; routed from parseArgs (handles zemo cat and zemo cat <topic>) and dispatched in run.
  • New doCat (env → file path resolution) and printFile (path-based, testable) helpers.
  • Topic name validation reuses paths.isValidTopic (rejects path-traversal, dots, spaces, multibyte) with a friendly stderr message and exit code 1.
  • Missing scratch / topic file → zemo: no such file: <path> to stderr, exit 1 (standard cat-like behaviour).
  • File contents are streamed via Io.Reader.streamRemaining so memory usage is bounded by a 4 KiB read buffer regardless of file size.
  • README: added zemo cat to Features and Usage sections.
  • HELP_TEXT: added zemo cat and zemo cat <topic> lines.

Testing

  • zig build test passes locally
  • Manually verified the affected command(s):
    • zig build run -- cat zemo prints ~/memo/topics/zemo.md
    • zig build run -- cat prints scratch
    • zig build run -- cat doesnotexist → stderr zemo: no such file: ... and exit 1
  • Cross-build check (if touching platform-specific code): zig build -Dtarget=x86_64-windows / -Dtarget=x86_64-macos

New tests added:

  • parseArgs: cat without topic / parseArgs: cat with topic / parseArgs: cat too many args — parser-level
  • printFile: prints file contents to stdout — integration test using std.testing.tmpDir and Io.Writer.Allocating to capture output
  • printFile: missing file → exit 1, stderr message — verifies error path and exit code

Notes for reviewers

  • printFile was extracted from doCat to keep the testable surface path-based (mirrors the listTopics / doLs split from feat: add zemo ls to list topics #6).
  • Topic-name validation lives in doCat rather than parseArgs, matching the existing pattern for zemo <topic> (openTopic). This keeps parseArgs payload-agnostic and consolidates user-facing validation messages in the dispatcher.
  • The relative-ZEMO_DIR fix from feat: add zemo ls to list topics #6 (centralized in paths.memoDir) carries over for free — doCat calls paths.memoDir and benefits from the absolute-path normalization.

@hidetzu hidetzu merged commit 6968b7c into main May 6, 2026
6 checks passed
@hidetzu hidetzu deleted the feat/zemo-cat branch May 6, 2026 01:05
@hidetzu hidetzu mentioned this pull request May 6, 2026
3 tasks
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 cat command

1 participant