all or some

This commit is contained in:
root 2025-06-25 17:25:05 -04:00
parent a7775c999c
commit 25ca294287
2 changed files with 34 additions and 0 deletions

BIN
main

Binary file not shown.

34
main.go
View File

@ -1,6 +1,8 @@
package main package main
import ( import (
"flag"
"strings"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net" "net"
@ -12,7 +14,33 @@ import (
"golang.org/x/sys/unix" "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() { 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")) headerStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("63"))
ipStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("203")) ipStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("203"))
upStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("42")) upStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("42"))
@ -32,6 +60,7 @@ func main() {
fmt.Println("Error listing links:", err) fmt.Println("Error listing links:", err)
return return
} }
for _, link := range links { for _, link := range links {
attrs := link.Attrs() attrs := link.Attrs()
@ -39,6 +68,11 @@ func main() {
continue continue
} }
if filtering {
if _, ok := filterSet[attrs.Name]; !ok {
continue
}
}
state := downStyle.Render("DOWN") state := downStyle.Render("DOWN")
if attrs.Flags&net.FlagUp != 0 { if attrs.Flags&net.FlagUp != 0 {
state = upStyle.Render("UP") state = upStyle.Render("UP")