- 04-02-SUMMARY.md: --filter and --read flags wired, pcap mode, deriveOutputPath - STATE.md: advanced to plan 2/2, updated decisions, session record - ROADMAP.md: phase 4 marked Complete (2/2 plans)
4.6 KiB
phase, plan, subsystem, tags, dependency_graph, tech_stack, key_files, decisions, metrics
| phase | plan | subsystem | tags | dependency_graph | tech_stack | key_files | decisions | metrics | |||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 04-power-user-features | 02 | cmd/netsynth |
|
|
|
|
|
|
Phase 04 Plan 02: CLI wiring for --filter and --read flags
One-liner: --filter and --read flags wired into Cobra CLI with mutual exclusion, BPF pre-validation, pcap file processing path, output filename derivation, and bookend messages.
What Was Built
cmd/netsynth/main.go
New global variables:
bpfFilter string— bound to--filterflag (BPF expression in tcpdump syntax)readPath string— bound to--readflag (pcap file path)
New deriveOutputPath function:
Replaces file extension with .mp3. capture.pcap → capture.mp3, noext → noext.mp3. Uses filepath.Ext so only the last extension is replaced (e.g., traffic.pcap.gz → traffic.pcap.mp3).
Updated run() function:
- Validates
--readand-imutual exclusion with clear error (D-03) - Returns error mentioning
--readwhen neither source is provided - Pre-validates BPF filter via
capture.ValidateBPFFilterbefore any capture starts (CAPT-05) - Derives output path from input pcap if
--outputnot given (D-05) - Branches to
runLiveModeorrunPcapMode
New runLiveMode function:
Extracted from the original run(). Now passes bpfFilter to capture.StartCapture(ctx, ifaceName, bpfFilter).
New runPcapMode function:
- Prints
"Reading <file>..."bookend start message (D-06) - Opens pcap via
capture.ReadPcapFile(readPath, bpfFilter)with optional software BPF - Classifies packets, sets
cp.Timestamp = pkt.Metadata().CaptureInfo.Timestampfor timestamp-based windowing (D-01) - Aggregates via
aggregate.AggregatePcap(offline, timestamp-based) --verbosesupported viaonSnapshotcallback (D-07)- Prints protocol summary before encoding (D-08 pattern preserved)
- Returns clear error if zero snapshots:
"pcap file %q contains no packets (after filtering)"(Pitfall 4) - Encodes and prints
"Saved..."bookend end message (D-06)
cmd/netsynth/main_test.go
New test functions:
| Test | What it checks |
|---|---|
TestFlagMutualExclusion |
--read + -i together returns "mutually exclusive" error |
TestMissingSource |
No source returns "interface required" error mentioning --read |
TestDeriveOutputPath |
Path derivation: .pcap→.mp3, no ext→.mp3, /tmp/net.pcap→/tmp/net.mp3 |
TestFilterFlagRegistered |
--filter flag is registered on rootCmd |
TestReadFlagRegistered |
--read flag is registered on rootCmd |
TestInvalidBPFFilter |
Invalid BPF expression returns error containing "invalid" |
TestHelpOutputNewFlags |
Usage string contains --filter and --read |
Updated newTestCmd() helper to wire bpfFilter, readPath, outputPath globals.
Updated TestMissingInterfaceFlag to verify error also mentions --read.
Commits
| Task | Commit | Description |
|---|---|---|
| Task 1 (RED) | 09e78bf |
test(04-02): add failing tests for --filter, --read flags |
| Task 1 (GREEN) | 4adb3c4 |
feat(04-02): wire --filter and --read flags into CLI |
Deviations from Plan
None — plan executed exactly as written.
Known Stubs
None. All flags are fully wired and functional. The pcap mode end-to-end path is complete.
Self-Check: PASSED
Files verified:
- /home/dev/workspace/yoloyolo/.claude/worktrees/agent-a90dedf3/cmd/netsynth/main.go: FOUND
- /home/dev/workspace/yoloyolo/.claude/worktrees/agent-a90dedf3/cmd/netsynth/main_test.go: FOUND
Commits verified: 09e78bf, 4adb3c4 in git log.
All tests green: go test ./... -count=1 passed 6 packages.
Build succeeded: go build ./... clean.