Skip to content

Feature/json export and yaml watch#23

Merged
nagayon-935 merged 2 commits into
mainfrom
feature/json-export-and-yaml-watch
May 16, 2026
Merged

Feature/json export and yaml watch#23
nagayon-935 merged 2 commits into
mainfrom
feature/json-export-and-yaml-watch

Conversation

@nagayon-935

Copy link
Copy Markdown
Owner

No description provided.

nagayon-935 and others added 2 commits May 16, 2026 14:22
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
@nagayon-935 nagayon-935 merged commit d437a36 into main May 16, 2026
1 check passed
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