Skip to content

feat(push,sync,diff): support multiple files and --all flag - #36

Merged
hirano00o merged 3 commits into
mainfrom
feature/multi-file
Mar 16, 2026
Merged

hirano00o merged 3 commits into
mainfrom
feature/multi-file

Conversation

@hirano00o

@hirano00o hirano00o commented Mar 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • hb push, hb sync, hb diff の各コマンドで複数ファイルを一括処理できるようにした
  • --all フラグで globMD 経由のカレントディレクトリ配下の全 .md ファイルを対象にできるようにした
  • エラーが発生しても他のファイルの処理を継続し、最後に errors.Join でまとめて報告する

Changes

  • push.go: cobra.ExactArgs(1)cobra.MinimumNArgs(0)pushOne ヘルパーに処理を切り出し、ループで複数ファイル処理
  • sync.go: 同様に複数ファイル対応。editUrl なしのファイルはエラー集計してスキップ
  • diff.go: 同様に複数ファイル対応。editUrl なしのファイルはメッセージ表示してスキップ(エラーなし)

Test plan

  • go test ./internal/cli/... が全て PASS することを確認
  • hb push file1.md file2.md で2ファイルが順に処理されること
  • hb push --all でカレントディレクトリ配下の全 .md が処理されること
  • --all と引数を同時指定するとエラーになること
  • 1ファイルが失敗しても他が継続されること

push/sync/diff accepted only a single file argument. This made it
cumbersome to batch-update multiple entries; users had to loop themselves
or push each file individually. Supporting variadic args and --all lets a
single invocation cover a whole directory of articles.

Changes:
- cobra.ExactArgs(1) → cobra.MinimumNArgs(0) for push, sync, diff
- Add --all flag that runs globMD(".") and processes every .md found
- --all and positional args are mutually exclusive; neither alone is an error
- Multi-file loop continues on per-file errors and reports all failures via
  errors.Join at the end, so one bad file does not abort the rest
- push --all: CREATE entries without editUrl (unchanged behaviour)
- sync --all: skip entries without editUrl, collect as errors
- diff --all: print "No editUrl" message for unpublished entries, no error
- Refactor push RunE into pushOne(ctx, cmd, client, path, …) helper to
  keep the loop body readable
- Add tests: NoArgs, AllAndArgs, MultipleFiles, All, ErrorContinues
The outer loop already wraps errors with "%s: %w" (path prefix),
so including the path again inside pushOne caused double-path output
like "file.md: read file.md: open file.md: ...".
TestDiff_NoEditURL_NewEntry and TestSync_NoEditURL called
newClientFromConfig() before reaching the editUrl check, so they
failed in CI where no config exists. Add the same t.Setenv pattern
used by other tests in the same files.
@hirano00o
hirano00o merged commit d45d92d into main Mar 16, 2026
2 checks passed
@hirano00o
hirano00o deleted the feature/multi-file branch March 16, 2026 14:51
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