fix: dns resolution taking long and add caching options (#8)
This commit is contained in:
21
cmd/top.go
21
cmd/top.go
@@ -6,16 +6,15 @@ import (
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/karol-broda/snitch/internal/config"
|
||||
"github.com/karol-broda/snitch/internal/resolver"
|
||||
"github.com/karol-broda/snitch/internal/tui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// top-specific flags
|
||||
var (
|
||||
topTheme string
|
||||
topInterval time.Duration
|
||||
topResolveAddrs bool
|
||||
topResolvePorts bool
|
||||
topTheme string
|
||||
topInterval time.Duration
|
||||
)
|
||||
|
||||
var topCmd = &cobra.Command{
|
||||
@@ -29,11 +28,16 @@ var topCmd = &cobra.Command{
|
||||
theme = cfg.Defaults.Theme
|
||||
}
|
||||
|
||||
// configure resolver with cache setting
|
||||
effectiveNoCache := noCache || !cfg.Defaults.DNSCache
|
||||
resolver.SetNoCache(effectiveNoCache)
|
||||
|
||||
opts := tui.Options{
|
||||
Theme: theme,
|
||||
Interval: topInterval,
|
||||
ResolveAddrs: topResolveAddrs,
|
||||
ResolvePorts: topResolvePorts,
|
||||
ResolveAddrs: resolveAddrs,
|
||||
ResolvePorts: resolvePorts,
|
||||
NoCache: effectiveNoCache,
|
||||
}
|
||||
|
||||
// if any filter flag is set, use exclusive mode
|
||||
@@ -62,9 +66,8 @@ func init() {
|
||||
// top-specific flags
|
||||
topCmd.Flags().StringVar(&topTheme, "theme", cfg.Defaults.Theme, "Theme for TUI (see 'snitch themes')")
|
||||
topCmd.Flags().DurationVarP(&topInterval, "interval", "i", time.Second, "Refresh interval")
|
||||
topCmd.Flags().BoolVar(&topResolveAddrs, "resolve-addrs", !cfg.Defaults.Numeric, "Resolve IP addresses to hostnames")
|
||||
topCmd.Flags().BoolVar(&topResolvePorts, "resolve-ports", false, "Resolve port numbers to service names")
|
||||
|
||||
// shared filter flags
|
||||
// shared flags
|
||||
addFilterFlags(topCmd)
|
||||
addResolutionFlags(topCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user