refactor: extract common filter logic into shared runtime

This commit is contained in:
Karol Broda
2025-12-17 17:33:01 +01:00
parent c543a8a4e9
commit 3ce1ce8aed
13 changed files with 309 additions and 216 deletions

View File

@@ -40,12 +40,11 @@ func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/snitch/snitch.toml)")
rootCmd.PersistentFlags().Bool("debug", false, "enable debug logs to stderr")
// add top's filter flags to root so `snitch -l` works
// add top's flags to root so `snitch -l` works (defaults to top command)
cfg := config.Get()
rootCmd.Flags().StringVar(&topTheme, "theme", cfg.Defaults.Theme, "Theme for TUI (dark, light, mono, auto)")
rootCmd.Flags().DurationVarP(&topInterval, "interval", "i", 0, "Refresh interval (default 1s)")
rootCmd.Flags().BoolVarP(&topTCP, "tcp", "t", false, "Show only TCP connections")
rootCmd.Flags().BoolVarP(&topUDP, "udp", "u", false, "Show only UDP connections")
rootCmd.Flags().BoolVarP(&topListen, "listen", "l", false, "Show only listening sockets")
rootCmd.Flags().BoolVarP(&topEstab, "established", "e", false, "Show only established connections")
// shared filter flags for root command
addFilterFlags(rootCmd)
}