feat(push,sync,diff): support multiple files and --all flag - #36
Merged
Merged
Conversation
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.
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.
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と引数を同時指定するとエラーになること