feat(watch): add hb watch command for auto-push on file change - #42
Merged
Conversation
Adds `hb watch [<file>]` and `hb watch --dir <dir>` to monitor local Markdown files with fsnotify and push changes to Hatena Blog automatically after a configurable debounce delay (default 500ms). Graceful shutdown is handled by signal.NotifyContext (SIGINT/SIGTERM). pushFileFunc is exposed as a package-level variable for test injection.
- Use cmd.Flags().Changed("dir") instead of dir != "." for mutual
exclusion check so that explicit --dir . is also detected
- Stop all pending debounce timers before returning on ctx.Done()
to avoid goroutine leaks after shutdown
- Set cmd context from runWatch so pushFile can propagate cancellation
to push subcommands
- Guard AfterFunc callback with ctx.Err() check
- Add TestWatch_Debounce to verify rapid saves produce only one push
hirano00o
force-pushed
the
feature/watch
branch
from
March 22, 2026 13:43
91d445f to
a917772
Compare
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 watch [<file>]andhb watch --dir <dir>to monitor local Markdown files for changes and automatically push to Hatena Blog--debounce) prevents rapid saves from triggering multiple pushessignal.NotifyContext(SIGINT/SIGTERM); displays "Stopped." on exitpushFileFuncpackage-level variable enables test injection without real API calls.mdfiles created inside a watched directory are automatically added to the watch setTest plan
TestWatch_MutuallyExclusive—--dir+ file argument returns an errorTestWatch_NoMDFiles— empty directory prints "No .md files found" and exits cleanlyTestWatch_FileChange_TriggersPush— writing to a watched file triggerspushFileFuncwith the correct path within the debounce windowgo test ./...all PASSgo vet ./...clean