feat(02-03): wire -o output flag and snapshot accumulator stub into CLI
- Add outputPath var and -o/--output Cobra flag (OUT-01) - Default output path resolves to netsynth-<timestamp>.mp3 when -o not provided (D-15) - Snapshot accumulator collects all WindowSnapshots for Phase 3 synthesis wiring - TODO(phase-3) marker for encode.RunSynthesis integration
This commit is contained in:
+14
-1
@@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ var (
|
|||||||
ifaceName string
|
ifaceName string
|
||||||
listIfaces bool
|
listIfaces bool
|
||||||
verbose bool
|
verbose bool
|
||||||
|
outputPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -33,6 +35,7 @@ func main() {
|
|||||||
rootCmd.Flags().StringVarP(&ifaceName, "interface", "i", "", "Network interface to capture on (required unless --list-interfaces)")
|
rootCmd.Flags().StringVarP(&ifaceName, "interface", "i", "", "Network interface to capture on (required unless --list-interfaces)")
|
||||||
rootCmd.Flags().BoolVar(&listIfaces, "list-interfaces", false, "List available network interfaces and exit")
|
rootCmd.Flags().BoolVar(&listIfaces, "list-interfaces", false, "List available network interfaces and exit")
|
||||||
rootCmd.Flags().BoolVar(&verbose, "verbose", false, "Print per-window protocol activity to stderr")
|
rootCmd.Flags().BoolVar(&verbose, "verbose", false, "Print per-window protocol activity to stderr")
|
||||||
|
rootCmd.Flags().StringVarP(&outputPath, "output", "o", "", "Output MP3 file path (default: netsynth-<timestamp>.mp3)")
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -45,6 +48,11 @@ func run(cmd *cobra.Command, args []string) error {
|
|||||||
return runListInterfaces()
|
return runListInterfaces()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve default output path (D-15 / OUT-01)
|
||||||
|
if outputPath == "" {
|
||||||
|
outputPath = fmt.Sprintf("netsynth-%s.mp3", time.Now().Format("20060102-150405"))
|
||||||
|
}
|
||||||
|
|
||||||
// Require -i flag
|
// Require -i flag
|
||||||
if ifaceName == "" {
|
if ifaceName == "" {
|
||||||
return fmt.Errorf("interface required: use -i <interface> or --list-interfaces to see available interfaces")
|
return fmt.Errorf("interface required: use -i <interface> or --list-interfaces to see available interfaces")
|
||||||
@@ -80,12 +88,17 @@ func run(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
snapshots := aggregate.Aggregate(ctx.Done(), classified, aggregate.DefaultWindowMs, onSnapshot)
|
snapshots := aggregate.Aggregate(ctx.Done(), classified, aggregate.DefaultWindowMs, onSnapshot)
|
||||||
|
|
||||||
// Consume snapshots and accumulate totals
|
// Accumulate snapshots for synthesis (Phase 3 will pass to encode.RunSynthesis)
|
||||||
totals := make(map[classify.TrafficClass]int64)
|
totals := make(map[classify.TrafficClass]int64)
|
||||||
|
var collectedSnapshots []classify.WindowSnapshot
|
||||||
for snap := range snapshots {
|
for snap := range snapshots {
|
||||||
|
collectedSnapshots = append(collectedSnapshots, snap)
|
||||||
aggregate.AccumulateTotals(totals, snap)
|
aggregate.AccumulateTotals(totals, snap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(phase-3): Pass collectedSnapshots to encode.RunSynthesis(collectedSnapshots, outputPath)
|
||||||
|
_ = collectedSnapshots
|
||||||
|
|
||||||
// Print exit summary (CLAS-03)
|
// Print exit summary (CLAS-03)
|
||||||
dropped := atomic.LoadInt64(droppedPtr)
|
dropped := atomic.LoadInt64(droppedPtr)
|
||||||
if dropped > 0 {
|
if dropped > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user