diff --git a/main b/main index 75cd8a6..6a8eedc 100755 Binary files a/main and b/main differ diff --git a/main.go b/main.go index b51ef25..edea80e 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "flag" + "strings" "fmt" "io/ioutil" "net" @@ -12,7 +14,33 @@ import ( "golang.org/x/sys/unix" ) +type stringSlice []string + +func (s *stringSlice) String() string { + return strings.Join(*s, ",") +} + +func (s *stringSlice) Set(value string) error { + *s = append(*s, value) + return nil +} + + func main() { + + var interfaces stringSlice + flag.Var(&interfaces, "iface", "Interface(s) to filter on (can be specified multiple times)") + flag.Parse() + + // Build lookup map + filterSet := make(map[string]struct{}) + for _, name := range interfaces { + filterSet[name] = struct{}{} + } + + // Determine if we are filtering at all + filtering := len(filterSet) > 0 + headerStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("63")) ipStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("203")) upStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("42")) @@ -32,6 +60,7 @@ func main() { fmt.Println("Error listing links:", err) return } + for _, link := range links { attrs := link.Attrs() @@ -39,6 +68,11 @@ func main() { continue } + if filtering { + if _, ok := filterSet[attrs.Name]; !ok { + continue + } + } state := downStyle.Render("DOWN") if attrs.Flags&net.FlagUp != 0 { state = upStyle.Render("UP")