Feature/json export and yaml watch#23
Merged
Merged
Conversation
JSON Export (-j / --json-output <file>):
- New internal/stats/export.go: ExportSnapshot, TargetSummary, PortSummary
types and BuildSnapshot() for thread-safe snapshot generation
- writeJSONSnapshot() writes atomically via .tmp+rename to avoid partial reads
- Periodic goroutine writes every 5s; final snapshot written on exit
- YAML key json-output also accepted so the path can live in hosts files
YAML Auto-Reload (-f <hosts.yaml>):
- New internal/watcher/watcher.go wraps fsnotify with 200ms debounce;
handles vim/nano rename-on-save via re-add on Create events
- validateHostsDoc() checks hosts non-empty, interval 100-60000ms,
timeout 10-30000ms, size 1-9872 bytes, count >= 0, not (ipv4 && ipv6)
- run() restructured as a loop: each iteration starts fresh targets,
pinger, port-checker, and watcher; on valid YAML change the loop
re-enters with updated hosts/config (stats reset, full restart)
- RunOptions gains ExternalCloseCh (<-chan struct{}) and ExternalLogCh
(<-chan string); the TUI refresh goroutine shows "[yellow]Reloading..."
and stops when ExternalCloseCh is closed, and forwards watcher error
messages to the Log pane via ExternalLogCh
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous implementation watched the file inode directly. Editors like vim and nano save atomically via write-to-tmp then rename-over, which silently invalidates the inode watch. Fix: watch the parent directory and filter events by the absolute path of the target file. Write events (direct saves) and Create events (rename-over saves) are both detected regardless of the editor used. New tests: TestWatch_AtomicRename, TestWatch_OtherFilesIgnored
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.
No description provided.